import sys input=sys.stdin.readline a=int(input()) import math for i in range(a): n,k,x=map(int,input().split()) z=list(map(int,input().split())) dp=[[[0 for i in range(2)] for i in range(k+1)] for i in range(n)] # dp[i][j][0] denotest ith index tak j use karlei #and the current maximum is how much # dp[i][j][1] denotes ith index tak j use karlie and overall maximum is how much maxa=0 for i in range(len(z)): for j in range(k+1): if(i+1<j): dp[i][j][0]=-math.inf dp[i][j][1]=-math.inf continue if(i==0 and j==0): dp[i][j][0]=max(0,z[i]-x) dp[i][j][1]=dp[i][j][0] elif(i==0 and j==1): dp[i][j][0]=max(z[i]+x,0) dp[i][j][1]=dp[i][j][0] elif(j==0): dp[i][j][0]=max(dp[i-1][j][0]+z[i]-x,0) dp[i][j][1]=max(dp[i-1][j][1],dp[i][j][0]) else: dp[i][j][0]=max(dp[i-1][j-1][0]+z[i]+x,dp[i-1][j][0]+z[i]-x,0) dp[i][j][1]=max(dp[i][j][0],dp[i-1][j][1],dp[i-1][j-1][1]) if(j==k): maxa=max(maxa,dp[i][j][1]) print(maxa)