public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		StringBuilder out = new StringBuilder();
		int times = in.nextInt();
		for (int i = 0; i < times; i++) {
			int nCoins = in.nextInt();
			int[] c = new int[nCoins];
			for (int j = 0; j < c.length; j++)
				c[j] = in.nextInt();
			Arrays.sort(c);
			int sum = 0, ans = 0;
			for (int j = 0; j < c.length; j++)
				sum += c[j];
			ans = sum;
			boolean[][] cr = new boolean[nCoins][sum + 1];
			for (int j = 0; j < c.length; j++) {
				ans = Math.min(Math.abs(c[j] * 2 - sum), ans);
				cr[j][0] = true;
				if (j == 0)
					cr[j][c[j]] = true;
				else
					for (int k = 0; k <= sum; k++) {
						cr[j][k] |= cr[j - 1][k];
						if (k >= c[j] && cr[j - 1][k - c[j]]) {
							ans = Math.min(Math.abs(k * 2 - sum), ans);
							cr[j][k] = true;
						}
					}
			}
			out.append(ans + "\n");
		}
		System.out.print(out);
	}