usingnamespace std; #define ll int const ll N = 35, inf = 2147483647; ll n, v[N], t, ans;
ll read(){ ll s = 0, w = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { s = (s << 1) + (s << 3) + ch - '0'; ch = getchar(); } return s * w; }
intanss(){ ll sum1 = 0, sum2 = 0; for (int i = 1; i <= (n + 1) / 2; i++) sum1 += v[i]; for (int i = (n + 1) / 2 + 1; i <= n; i++) sum2 += v[i]; returnabs(sum1 - sum2); }
voidsa(){ double s = 5000, f = 1e-10, chT = 0.91; for (double i = s; i > f; i *= chT) { ll x = rand() % n + 1, y = rand() % n + 1; swap(v[x], v[y]); ll sum = anss(); if (sum < ans) ans = sum; else { if ((exp((ans - sum) / i)) < (double(rand()) / RAND_MAX)) swap(v[x], v[y]); } } }
intmain(){ srand((int) time(0)); t = read(); while (t--) { ans = inf; n = read(); for (int i = 1; i <= n; i++) v[i] = read(); for (int i = 1; i <= 1000; i++) sa(); cout << ans << endl; } return0; }