#include <bits/stdc++.h>
using namespace std;
int main() {
  int tests;
  for (scanf("%d", &tests); tests; --tests) {
    int n, x;
    scanf("%d %d", &n, &x);
    for (int i = 1; i < n; ++i) {
      int y;
      scanf("%d", &y);
      x -= y;
    }
    x %= n;
    if (x <= 0) x += n;
    printf("%d\n", x);
  }
  return 0;
}
