CF BUDDY
← Problems·

1994D · Funny Game

1900 · constructive algorithms, dsu, graphs

Problem: Vanya has a graph with nn vertices (numbered from 11 to nn) and an array aa of nn integers; initially, there are no edges in the graph. Vanya got bored, and to have fun, he decided to perform n1n - 1 operations.

Operation number xx (operations are numbered in order starting from 11) is as follows:

  • Choose 22 different numbers 1u,vn1 \leq u,v \leq n, such that auav|a_u - a_v| is divisible by xx.
  • Add an undirected edge between vertices uu and vv to the graph.

Help Vanya get a connected*^{\text{*}} graph using the n1n - 1 operations, or determine that it is impossible.

Input Format: Each test consists of multiple test cases. The first line contains an integer tt (1t1031 \le t \le 10^{3}) — the number of test cases. Then follows the description of the test cases.

The first line of each test case contains the number nn (1n20001 \leq n \leq 2000) — the number of vertices in the graph.

The second line of each test case contains nn numbers a1,a2,ana_1, a_2, \cdots a_n (1ai1091 \leq a_i \leq 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 20002000.

Output Format: For each test case, if there is no solution, then output "No" (without quotes).

Otherwise, output "Yes" (without quotes), and then output n1n - 1 lines, where in the ii-th line, output the numbers uu and vv that need to be chosen for operation ii.

You can output each letter in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as a positive answer).

Note: Let's consider the second test case.

  • First operation (x=1)(x = 1): we can connect vertices 44 and 11, since a4a1=1399=86=86|a_4 - a_1| = |13 - 99| = |-86| = 86, and 8686 is divisible by 11.

  • Second operation (x=2)(x = 2): we can connect vertices 22 and 11, since a2a1=799=92=92|a_2 - a_1| = |7 - 99| = |-92| = 92, and 9292 is divisible by 22.

  • Third operation (x=3)(x = 3): we can connect vertices 33 and 22, since a3a2=17=6=6|a_3 - a_2| = |1 - 7| = |-6| = 6, and 66 is divisible by 33.

Sample Cases

Case 1

Input

8
2
1 4
4
99 7 1 13
5
10 2 31 44 73
5
87 6 81 44 32
5
62 35 33 79 16
5
6 51 31 69 42
5
52 63 25 21 5
12
33 40 3 11 31 43 37 8 50 5 12 22

Output

YES
2 1
YES
4 1
2 1
3 2
YES
5 1
4 1
3 1
2 1
YES
4 1
3 1
2 1
5 4
YES
3 1
5 1
2 1
4 2
YES
4 1
5 1
2 1
3 2
YES
2 1
5 2
3 1
4 3
YES
9 1
12 9
11 1
10 1
6 1
7 6
2 1
8 2
5 2
3 1
4 1

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback