There are many 000 and 111 in both bit and BIT.
In BIT, the definition of 000 and 111 is also somehow ambiguous. 000 can sometimes become 111 and vice versa.
Now, given an event string containing only AAA and BBB with length nnn, you're required to answer QQQ questions (lreal,rreal,x)(l_{real},r_{real},x)(lreal,rreal,x) which ask what will binary string xxx be after experiencing the events in interval [lreal,rreal][l_{real},r_{real}][lreal,rreal] (The leftmost bit is the most significant bit for xxx).
Here's the illustration for the event AAA, BBB.
AAA: change 000 in xxx to 111 and change 111 in xxx to 000 simultaneously.
BBB: execute x=x+1x=x+1x=x+1 where xxx is viewed as an integer in binary representation. Specially, if xxx contains only 111, xxx will become a binary string with all 000.
You are required to answer each problem online. For this propose, if we ask (l,r)(l,r)(l,r) in the i−i-i−th query, it means the actually asked segment is defined as:
lreal=min((ansi−1⊕l)%n+1, (ansi−1⊕r)%n+1)l_{real} = min((ans_{i-1}\oplus l)\%n+1,\ (ans_{i-1}\oplus r)\%n+1)lreal=min((ansi−1⊕l)%n+1, (ansi−1⊕r)%n+1)
rreal=max((ansi−1⊕l)%n+1, (ansi−1⊕r)%n+1)r_{real} = max((ans_{i-1}\oplus l)\%n+1,\ (ans_{i-1}\oplus r)\%n+1)rreal=max((ansi−1⊕l)%n+1, (ansi−1⊕r)%n+1)
where ⊕\oplus⊕ is the exclusive OR operation and ansi−1ans_{i-1}ansi−1 is the answer for the (i−1)−(i-1)-(i−1)−th query (viewed as an integer in binary representation) with ans0=0ans_0=0ans0=0.