Task
Valerio is currently visiting Poland, and on the street he found two strings and of length each, consisting of 's and 's.
When he returned home, he decided to write a program that chooses two contiguous substrings of length , one from and one from , then interprets them as binary numbers (i.e. numbers written in base 2) and computes their sum.
Unfortunately Valerio made a mistake: he decided to store the result of the sum in an -bit variable (i.e., a variable that can store numbers from to inclusive), but in some cases the sum can be too larger! Help him to verify the correctness of the result.
You are given queries, each consisting of integers , and .
For each query, determine whether Valerio's program is correct for the strings and .
In other words, you need to determine whether the sum of the numbers with binary representation and is strictly less than .
Input data
The input file consists of:
- a line containing integer .
- a line containing string of length .
- a line containing string of length .
- a line containing integer .
- lines, the -th of which consisting of integers , and .
Output data
The output file must contain a single line consisting of the integers: the -th value must be if Valerio's program gives the correct result to query , otherwise the value must be .
Constraints and clarifications
- .
- and consist of characters
0
and1
. - .
- for each .
- for each .
- for each .
# | Points | Constraints |
---|---|---|
1 | 0 | Examples. |
2 | 40 | and |
3 | 30 | for each |
4 | 30 | No additional limitations. |
Example 1
stdin
7
1001010
0111101
5
0 0 1
0 0 3
0 0 4
0 4 3
4 5 2
stdout
1 1 0 0 1
Explanation
In the first sample case there are queries:
- in the first query the substrings are
1
and0
, and their sum is , less than ; - in the second query the substrings are
100
and011
, and their sum is , less than ; - in the third query the substrings are
1001
and0111
, and their sum is , not less than ; - in the fourth query the substrings are
100
and101
, and their sum is , not less than ; - in the fifth query the substrings are
01
and01
, and their sum is , less than .
Example 2
stdin
12
101000010101
011110101110
7
1 5 4
8 2 3
9 4 2
10 3 1
0 0 3
0 0 6
3 5 6
stdout
1 0 0 1 0 0 1