CF BUDDY
← Problems·

1562C · Rings

1500 · constructive algorithms, math

Problem: Somewhere in a parallel Middle-earth, when Saruman caught Frodo, he only found nn rings. And the ii-th ring was either gold or silver. For convenience Saruman wrote down a binary string ss of nn characters, where the ii-th character was 0 if the ii-th ring was gold, and 1 if it was silver.

Saruman has a magic function ff, which takes a binary string and returns a number obtained by converting the string into a binary number and then converting the binary number into a decimal number. For example, f(001010)=10,f(111)=7,f(11011101)=221f(001010) = 10, f(111) = 7, f(11011101) = 221.

Saruman, however, thinks that the order of the rings plays some important role. He wants to find 22 pairs of integers (l1,r1),(l2,r2)(l_1, r_1), (l_2, r_2), such that:

  • 1l1n1 \le l_1 \le n, 1r1n1 \le r_1 \le n, r1l1+1n2r_1-l_1+1\ge \lfloor \frac{n}{2} \rfloor
  • 1l2n1 \le l_2 \le n, 1r2n1 \le r_2 \le n, r2l2+1n2r_2-l_2+1\ge \lfloor \frac{n}{2} \rfloor
  • Pairs (l1,r1)(l_1, r_1) and (l2,r2)(l_2, r_2) are distinct. That is, at least one of l1l2l_1 \neq l_2 and r1r2r_1 \neq r_2 must hold.
  • Let tt be the substring s[l1:r1]s[l_1:r_1] of ss, and ww be the substring s[l2:r2]s[l_2:r_2] of ss. Then there exists non-negative integer kk, such that f(t)=f(w)kf(t) = f(w) \cdot k.

Here substring s[l:r]s[l:r] denotes slsl+1sr1srs_ls_{l+1}\ldots s_{r-1}s_r, and x\lfloor x \rfloor denotes rounding the number down to the nearest integer.

Help Saruman solve this problem! It is guaranteed that under the constraints of the problem at least one solution exists.

Input Format: Each test contains multiple test cases.

The first line contains one positive integer tt (1t1031 \le t \le 10^3), denoting the number of test cases. Description of the test cases follows.

The first line of each test case contains one positive integer nn (2n21042 \le n \le 2 \cdot 10^4) — length of the string.

The second line of each test case contains a non-empty binary string of length nn.

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

Output Format: For every test case print four integers l1l_1, r1r_1, l2l_2, r2r_2, which denote the beginning of the first substring, the end of the first substring, the beginning of the second substring, and the end of the second substring, respectively.

If there are multiple solutions, print any.

Note: In the first testcase f(t)=f(1111)=15f(t) = f(1111) = 15, f(w)=f(101)=5f(w) = f(101) = 5.

In the second testcase f(t)=f(111000111)=455f(t) = f(111000111) = 455, f(w)=f(000111)=7f(w) = f(000111) = 7.

In the third testcase f(t)=f(0000)=0f(t) = f(0000) = 0, f(w)=f(1000)=8f(w) = f(1000) = 8.

In the fourth testcase f(t)=f(11011)=27f(t) = f(11011) = 27, f(w)=f(011)=3f(w) = f(011) = 3.

In the fifth testcase f(t)=f(001111)=15f(t) = f(001111) = 15, f(w)=f(011)=3f(w) = f(011) = 3.

Sample Cases

Case 1

Input

7
6
101111
9
111000111
8
10000000
5
11011
6
001111
3
101
30
100000000000000100000000000000

Output

3 6 1 3
1 9 4 9
5 8 1 4
1 5 3 5
1 6 2 4
1 2 2 3
1 15 16 30

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