## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

## [Solution] Circular Spanning Tree Codeforces Solution | Codeforces Problem Solution 2022

D. Circular Spanning Tree
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There are $n$ nodes arranged in a circle numbered from $1$ to $n$ in the clockwise order. You are also given a binary string $s$ of length $n$.

Your task is to construct a tree on the given $n$ nodes satisfying the two conditions below or report that there such tree does not exist:

• For each node $i$ $\left(1\le i\le n\right)$, the degree of node is even if ${s}_{i}=0$ and odd if ${s}_{i}=1$.
• No two edges of the tree intersect internally in the circle. The edges are allowed to intersect on the circumference.

Note that all edges are drawn as straight line segments. For example, edge $\left(u,v\right)$ in the tree is drawn as a line segment connecting $u$ and $v$ on the circle.

Input

The input consists of multiple test cases. The first line contains a single integer $t$ $\left(1\le t\le 2\cdot {10}^{4}\right)$  — the number of test cases. Description of the test cases follows.

The first line of each test case contains a single integer $n$ $\left(2\le n\le 2\cdot {10}^{5}\right)$  — the number of nodes.

The second line of each test case contains a binary string $s$ of length $n$.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot {10}^{5}$.

Output

For each test case, if there does not exist a tree that satisfies the given conditions, then output "NO" (without quotes), otherwise output "YES" followed by the description of tree.

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

If there exists a tree, then output $n-1$ lines, each containing two integers $u$ and $v$ $\left(1\le u,v\le n,u\ne v\right)$ denoting an edge between $u$ and $v$ in the tree. If there are multiple possible answers, output any.