409353: GYM103488 G Generate 7 Colors

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

G. Generate 7 Colorstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Albedo needs some pieces of $$$7$$$ colors to paint PaiMonaLisa! Colors are numbered from $$$0$$$ to $$$6$$$. For color $$$i$$$, he needs exact $$$a_i$$$ pieces.

Albedo is a master alchemist. In one operation, he can generate a sequence $$$s$$$ of any length $$$k$$$. For the sequence $$$s_0,s_1,\dots,s_{k-1}$$$, $$$s_i=i\%7$$$ hold for $$$i\in [0,k-1]$$$. The $$$i$$$-th element indicates a piece of color $$$s_i$$$.

Please help Albedo find the minimum number of operations to generate exact $$$a_i$$$ pieces for all $$$7$$$ colors.

Input

The first line contains an integer $$$T(1\le T\le 10^5)$$$ — the number of test cases.

Each test case is described by $$$7$$$ integers $$$a_0,a_1\dots,a_6(1\le a_i\le 10^9)$$$ in one line — the pieces Albedo needs for $$$7$$$ colors respectively.

Output

For each test, output an integer in one line — the minimum number of operations to generate exact $$$a_i$$$ pieces for all $$$7$$$ colors. If it's impossible to do it, output -1.

ExampleInput
3
2 2 2 2 1 1 1
3 3 3 3 1 1 1
1 1 1 1 1 1 1000000000
Output
1
2
-1
Note

For test case $$$1$$$, Albedo can use $$$1$$$ operation and generate the sequence $$$[0,1,2,3,4,5,6,0,1,2,3]$$$.

For test case $$$2$$$, Albedo can use $$$2$$$ operations and generate $$$[0,1,2,3,4,5,6,0,1,2,3]$$$ and $$$[0,1,2,3]$$$ respectively.

加入题单

上一题 下一题 算法标签: