public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder out = new StringBuilder();
		while ((line = in.readLine()) != null && line.length() != 0) {
			int times = Integer.parseInt(line);
			for (int i = 0; i < times; i++) {
				int[] coef = readInts(in.readLine());
				long n = 1, next = n, k, d, ans = 0;
				d = Integer.parseInt(in.readLine().trim());
				k = Integer.parseInt(in.readLine().trim());
				while (next + d * n <= k)
					next += d * n++;
				for (int j = 1; j < coef.length; j++)
					ans += coef[j] * Math.pow(n, j - 1);
				out.append(ans + "\n");
			}

		}
		System.out.print(out);
	}