Solitaire

No attempts yetTime limit1sMemory limit256 MB

Problem

A row of N+1N+1 cells is numbered from 00 to NN, and cell ii holds the value ii. The game starts on cell 00 with the sum S=0S = 0. On each turn you roll a die, move that many cells to the right, and add the value of the cell you land on to SS. The game ends the moment you land on cell NN. A roll that would carry you past cell NN is discarded and you stay where you are. On cell N1N-1, for example, you have to wait for a 1 before you can make the last move.

Instead of a real die you get a generator, a sequence that uses each of the numbers 11 to 66 once. Repeat that sequence as many times as you need, and the result is the order of the rolls. If the generator is 2, 4, 6, 1, 3, 5, then the sixth roll is 5, the seventh is 2 again, then 4, then 6. A discarded roll still consumes one value from the generator.

Your score is the value of SS when the game ends. Given NN and the generator, compute the score.

Input

The first line contains the number of games TT (1T1001 \le T \le 100). Each game is given on two lines. The first line contains NN (1N10001 \le N \le 1000). The second line contains the generator, six integers that are the numbers 11 to 66 in some order.

Output

For each game, print its final score on its own line.