#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, r, a, s = 0;
    cin >> n >> r >> a;
    for (int i = 0, x; i < n - 2; ++i) cin >> x, s += x;
    int x = ((r == 1 ? a + s : a - s) + r - 1) % n;
    while (x < 1) x += n;
    cout << x << '\n';
  }
}
