Under construction

Still being built. Things may change

Parenthesis Sequence Character

Interview

Time limit1sMemory limit1024 MB

Summary
Given n and k, find the k-th character of the bracket string S_n = (S_{n-2} S_{n-1}), or print 0 if k exceeds its length.
Level

Medium5 of 10

Topics
Recursion, Math, String
Solved
No attempts yet

Problem

Define the sequence SS of strings as follows.

S1=S_1 = ()

S2=S_2 = ()

Sn=S_n = (Sn−2Sn−1S_{n-2} S_{n-1}) for n≥3n \geq 3

Find the kk-th character of SnS_n. The first character of SnS_n has index 11.

Input

The first line contains the number of test cases TT (1≤T≤1 0001 \leq T \leq 1\,000). Each of the next TT lines contains integers nn and kk (1≤n,k≤10181 \leq n, k \leq 10^{18}).

Output

For each test case, print the kk-th character of SnS_n. If kk is greater than the length of SnS_n, print 0 instead.

Hint

By the definition above,

S3=S_3 = (()())

S4=S_4 = (()(()()))

S5=S_5 = ((()())(()(()())))

Examples1

  1. Example 1

    Input
    3
    3 7
    4 7
    5 7
    
    Expected output
    0
    (
    )