#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int dp[100005], v[1005];///dp=v*100
int main()
{
int n, m, i, j, sum, s;
scanf("%d", &m);
while(m--)
{
scanf("%d", &n);
memset(dp, 0, sizeof(dp));
sum = 0;
for(i = 0 ; i <n ; i++)
{
scanf("%d", &v[i]);
sum += v[i];
}
s = sum/2;///感觉有点儿分界线的意思,中间数的分界线
for(i = 0 ; i < n ; i++)
for(j = s ; j >=v[i] ; j--)
{
dp[j] = max(dp[j], dp[j-v[i]]+v[i]);
}
printf("%d\n", sum-2*dp[s]);
}
return 0;
}