Generate 7 Colors
题号:NC232086
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

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 , hold for . 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.


输入描述:

The first line contains an integer  --- the number of test cases.
Each test case is described by 7 integers in one line --- the pieces Albedo needs for 7 colors respectively.

输出描述:

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.
示例1

输入

复制
3
2 2 2 2 1 1 1
3 3 3 3 1 1 1
1 1 1 1 1 1 1000000000

输出

复制
1
2
-1

说明

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.