题号:NC232086
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld
题目描述
Albedo needs some pieces of

colors to paint
PaiMonaLisa! Colors are numbered from

to

. For color

, he needs
exact 
pieces.
Albedo is a master alchemist. In one operation, he can generate a sequence

of any length

. For the sequence

,

hold for

. The

-th element indicates a piece of color

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

colors.
输入描述:
The first line contains an integer
--- the number of test cases.
Each test case is described by
integers
in one line --- the pieces Albedo needs for
colors respectively.
输出描述:
For each test, output an integer in one line --- the minimum number of operations to generate exact
pieces for all
colors. If it's impossible to do it, output -1.