Problem: Heidi got one brain, thumbs up! But the evening isn't over yet and one more challenge awaits our dauntless agent: after dinner, at precisely midnight, the N attendees love to play a very risky game...

Every zombie gets a number ni (1 ≤ ni ≤ N) written on his forehead. Although no zombie can see his own number, he can see the numbers written on the foreheads of all N - 1 fellows. Note that not all numbers have to be unique (they can even all be the same). From this point on, no more communication between zombies is allowed. Observation is the only key to success. When the cuckoo clock strikes midnight, all attendees have to simultaneously guess the number on their own forehead. If at least one of them guesses his number correctly, all zombies survive and go home happily. On the other hand, if not a single attendee manages to guess his number correctly, all of them are doomed to die!

Zombies aren't very bright creatures though, and Heidi has to act fast if she does not want to jeopardize her life. She has one single option: by performing some quick surgery on the brain she managed to get from the chest, she has the ability to remotely reprogram the decision-making strategy of all attendees for their upcoming midnight game! Can you suggest a sound strategy to Heidi which, given the rules of the game, ensures that at least one attendee will guess his own number correctly, for any possible sequence of numbers on the foreheads?

Given a zombie's rank R and the N - 1 numbers ni on the other attendees' foreheads, your program will have to return the number that the zombie of rank R shall guess. Those answers define your strategy, and we will check if it is flawless or not.

Input

The first line of input contains a single integer T (1 ≤ T ≤ 50000): the number of scenarios for which you have to make a guess.

The T scenarios follow, described on two lines each: 

  * The first line holds two integers, N (2 ≤ N ≤ 6), the number of attendees, and R (1 ≤ R ≤ N), the rank of the zombie who has to make the guess. 
  * The second line lists N - 1 integers: the numbers on the foreheads of all other attendees, listed in increasing order of the attendees' rank. (Every zombie knows the rank of every other zombie.) 

Output

For every scenario, output a single integer: the number that the zombie of rank R shall guess, based on the numbers ni on his N - 1 fellows' foreheads.

Examples

Input

4
2 1
1
2 2
1
2 1
2
2 2
2


Output

1
2
2
1


Input

2
5 2
2 2 2 2
6 4
3 2 6 1 2


Output

5
2

Note

For instance, if there were N = 2 two attendees, a successful strategy could be: 

  * The zombie of rank 1 always guesses the number he sees on the forehead of the zombie of rank 2. 
  * The zombie of rank 2 always guesses the opposite of the number he sees on the forehead of the zombie of rank 1. 

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int V, E, src, snk;
vector<int> la, nxt, oppo, capa;
void init() {
  E = 0;
  la.clear();
  nxt.clear();
  oppo.clear();
  capa.clear();
  la = vector<int>(V, -1);
}
void add(int u, int v, int c) {
  nxt.push_back(la[u]);
  la[u] = E++;
  oppo.push_back(v);
  capa.push_back(c);
}
queue<int> q;
int dist[100010];
bool bfs() {
  for (int i = 0; i < V; i++) dist[i] = -1;
  q.push(src);
  dist[src] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = la[u]; i != -1; i = nxt[i]) {
      int v = oppo[i];
      if (capa[i] && dist[v] == -1) {
        dist[v] = dist[u] + 1;
        q.push(v);
      }
    }
  }
  return dist[snk] != -1;
}
vector<int> laa;
int dfs(int u, int f) {
  if (u == snk) return f;
  for (int i = laa[u]; i != -1; i = nxt[i]) {
    laa[u] = i;
    int v = oppo[i];
    if (capa[i] && dist[v] == dist[u] + 1) {
      if (int tmp = dfs(v, min(capa[i], f))) {
        capa[i] -= tmp;
        capa[i ^ 1] += tmp;
        return tmp;
      }
    }
  }
  return 0;
}
int dinic() {
  int tf = 0;
  while (bfs()) {
    laa = la;
    while (int tmp = dfs(src, 1e9)) tf += tmp;
  }
  return tf;
}
int ans[7][1000010], po[7][7];
int TC, N, R;
int main() {
  for (int i = 2; i <= 6; i++) {
    po[i][0] = 1;
    for (int j = 1; j <= 6; j++) {
      po[i][j] = po[i][j - 1] * i;
    }
  }
  for (int n = 2; n <= 6; n++) {
    V = po[n][n] * 2 + 2, src = V - 2, snk = V - 1;
    init();
    for (int i = 0; i < po[n][n]; i++) {
      add(src, i, 1);
      add(i, src, 0);
      add(po[n][n] + i, snk, 1);
      add(snk, po[n][n] + i, 0);
      for (int j = 0; j < n; j++) {
        int a = i / po[n][j + 1];
        int b = i % po[n][j];
        add(j * po[n][n - 1] + a * po[n][j] + b, po[n][n] + i, 1);
        add(po[n][n] + i, j * po[n][n - 1] + a * po[n][j] + b, 0);
      }
    }
    dinic();
    for (int u = 0; u < po[n][n]; u++) {
      for (int i = la[u]; i != -1; i = nxt[i]) {
        int v = oppo[i];
        if (v == src || capa[i]) continue;
        ans[n][u] = ((v - po[n][n]) / po[n][u / po[n][n - 1]]) % n;
      }
    }
  }
  scanf("%d", &TC);
  while (TC--) {
    scanf("%d %d", &N, &R);
    R--;
    int sum = 0;
    for (int i = 0; i < N - 1; i++) {
      int t;
      scanf("%d", &t);
      t--;
      sum += po[N][i] * t;
    }
    sum += po[N][N - 1] * R;
    printf("%d\n", ans[N][sum] + 1);
  }
}