The Candy-Sharing Game

No attempts yetTime limit1sMemory limit128 MB

Problem

Younghee, a teacher at an algorithm kindergarten, handed out candy to the children at snack time. But the greedy children ignored the order and grabbed candy at random, so some ended up with a lot while others got almost none and started to cry.

So Younghee proposed a game. All the children sit in a circle. Each round consists of the following two steps, in order:

  1. Simultaneously, every child gives half of their candy to the child sitting to their right. In other words, each child keeps half of their own candy and receives half of the candy of the child on their left.
  2. If, as a result, any child now holds an odd number of candies, the teacher adds one candy to that child to make the count even.

After repeating this a number of times, every child ends up holding the same number of candies and the game ends.

Treating one ‘give half to the right’ step together with the following ‘teacher tops up’ step as a single round, determine how many rounds are needed until every child holds the same number of candies.

Note: if some children start with an odd number of candies, the teacher first tops them up to an even number, and this initial top-up is not counted as a round. Assume the teacher has more than enough candy.

Input

Input is given through standard input. The first line contains the number of test cases TT. Each test case consists of two lines. The first line contains the number of children NN (1N101 \le N \le 10), and the second line contains the number of candies each child starts with, C1,C2,,CNC_1, C_2, \dots, C_N (1Ci301 \le C_i \le 30), separated by spaces. The seating is arranged so that C2C_2 sits to the right of C1C_1, C3C_3 to the right of C2C_2, and so on, with C1C_1 sitting to the right of CNC_N.

Output

For each test case, print on its own line the number of rounds required until every child holds the same number of candies.