#P13996. 【MX-X19-T5】「FeOI Round 4.5」天使のクローバー

【MX-X19-T5】「FeOI Round 4.5」天使のクローバー

Description

Minori has a 0101 sequence ss, initially s=[0,1]s = [0, 1]. The indices of this sequence start from 00.

For a 0101 sequence s=[s0,,ss1]s = [s_0, \ldots, s_{\lvert s \rvert - 1}] with indices starting from 00, define the new 0101 sequence t=f(s)t = f(s) obtained after one ff-transformation as:

  • Initially, tt is empty.
  • For each i=0,,s1i = 0, \ldots, \lvert s \rvert - 1, append to the end of tt:
    • 11 copy of imod2i \bmod 2 (if si=0s_i = 0);
    • 33 copies of imod2i \bmod 2 (if si=1s_i = 1).
  • The indices of tt also start from 00.

For example, f([0,1])=[0,1,1,1]f([0, 1]) = [0, 1, 1, 1], and f([0,1,1,1])=[0,1,1,1,0,0,0,1,1,1]f([0, 1, 1, 1]) = [0, 1, 1, 1, 0, 0, 0, 1, 1, 1].

For a non-negative integer xx, define the notation fx(s)f^x(s) as the sequence obtained by applying the ff-transformation to ss consecutively xx times.

Minori will give you qq queries. Each query provides two non-negative integers x,rx, r, and asks for the value of the element at index rr in fx(s)f^x(s). If the length of fx(s)f^x(s) is r\le r, meaning there is no element at index rr, you must report that.

Input Format

The first line contains a positive integer qq.

The next qq lines each contain two non-negative integers x,rx, r.

Output Format

For each query, output one line. If an element at index rr exists, output a non-negative integer representing its value; otherwise, output -1.

3
1 3
1 4
2 4
1
-1
0

Hint

【Sample Explanation】

The initial sequence is [0,1][0,1].

After one transformation, the sequence becomes [0,1,1,1][0,1,1,1].

After two transformations, the sequence becomes [0,1,1,1,0,0,0,1,1,1][0,1,1,1,0,0,0,1,1,1].

【Data Range】

The test cases are not equally weighted. See the score column for details.

Test Case ID xx \le qq \le Special Properties Score
11 33 10410^4 None 1212
22 1010 2020 1919
33 101810^{18} 1010 No answer is 00
44 2020 x1012x\ge 10^{12} 1010
55 10410^4 None 4040

For all test cases, 1q1041\le q\le 10^4, 0x,r10180\le x,r\le 10^{18}.

Translated by DeepSeek V3.1