public static void main(String[] args) {
		PlayGame pg = new PlayGame();
		int[] w = {999, 1, 1, 1, 0};
		Double[] meYou = {0.0, 0.0};
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		while (N-- > 0) {
			int len = sc.nextInt();
			int[] a = new int[len];
			for (int i = len - 1; i >= 0; i--) {
				a[i] = sc.nextInt();
			}
			Double d = pg.solveGame(a);
			System.out.println(d.longValue());
		}
	}