import java.io.*;
import java.util.*;
public class POJ1976 {
static int dp[][] = new int[50000+5][4];//dp[i][j]:前i个车厢,用j个火车头拉,所能拉的最大人数
static int sum[] = new int[ 50000 + 5];
static int res;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int T = Integer.parseInt(st.nextToken());
for(int t = 1;t <= T;t++) {
st = new StringTokenizer(br.readLine());
Arrays.fill(sum, 0);
res = 0;
int N = Integer.parseInt(st.nextToken());
for(int i = 1;i <= N ; i++) {
Arrays.fill(dp[i], 0);
}
st = new StringTokenizer(br.readLine());
for(int i = 1;i <= N;i++) {
sum[i] = Integer.parseInt(st.nextToken());
sum[i] += sum[i-1];//前缀和
}
st = new StringTokenizer(br.readLine());
int M = Integer.parseInt(st.nextToken());
int k = 0;
for(int i = 1;i <= N;i++) {
k= i - M < 0 ? 0 : i -M ;
// System.out.println("k =="+ k);
for(int j = 1;j < 4;j++) {
dp[i][j]=Math.max(dp[i-1][j],dp[k][j-1]+sum[i]-sum[k]);
}
}
System.out.println(dp[N][3]);
}
}
}