Marin swung a racket at flies so hard that he hurt his elbow. His grandmother told him to rub herbs on it and the doctor prescribed a painkiller, but Marin ignored both and went looking for an answer in integer sequences.
He built a new sequence and named it the xorbonacci sequence. Its nth term is written xn, and it is defined like this.
- x1=a1
- x2=a2
- …
- xk=ak
- xn=xn−1⊕xn−2⊕⋯⊕xn−k when n>k
Marin says the pain goes away once someone answers his Q queries. Each query gives two numbers l and r, and its answer is
xl⊕xl+1⊕⋯⊕xr−1⊕xr
Here ⊕ is the bitwise XOR operation.