Parenthesis Sequence Character
InterviewTime limit1sMemory limit1024 MB
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.
Problem
Define the sequence of strings as follows.
()
()
() for
Find the -th character of . The first character of has index .
Input
The first line contains the number of test cases (). Each of the next lines contains integers and ().
Output
For each test case, print the -th character of . If is greater than the length of , print 0 instead.
Hint
By the definition above,
(()())
(()(()()))
((()())(()(()())))