Vietnamese and Bengali as well.
An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N}) = F_{i-1} \oplus F_{i−2} \oplus \ldots \oplus F_{i−N}$, where $\oplus$ denotes the bitwise XOR operation.
Recently, Chef has found an interesting sequence $S_1, S_2, \ldots$, which is obtained from prefix XORs of a XOR $N$-bonacci sequence $F_1, F_2, \ldots$. Formally, for each positive integer $i$, $S_i = F_1 \oplus F_2 \oplus \ldots \oplus F_i$. You are given the first $N$ elements of the sequence $F$, which uniquely determine the entire sequence $S$.
You should answer $Q$ queries. In each query, you are given an index $k$ and you should calculate $S_k$. It is guaranteed that in each query, $S_k$ does not exceed $10^{50}$.

-----Input-----
- The first line of the input contains two space-separated integers $N$ and $Q$.
- The second line contains $N$ space-separated integers $F_1, F_2, \ldots, F_N$.
- The following $Q$ lines describe queries. Each of these lines contains a single integer $k$.

-----Output-----
For each query, print a single line containing one integer $S_k$.

-----Constraints-----
- $1 \le N, Q \le 10^5$
- $0 \le F_i \le 10^9$ for each $i$ such that $1 \le i \le N$
- $1 \le k \le 10^9$

-----Example Input-----
3 4
0 1 2
7
2
5
1000000000

-----Example Output-----
3
1
0
0

Source: codechef | Difficulty: MEDIUM
Tags: Bit manipulation

Constructive algorithms

Mathematics

Data structures

Ad-hoc


Solutions:
(n, q) = map(int, input().split())
f = list(map(int, input().split()))
l = [0, f[0]]
for i in range(1, n, 1):
	l.append(l[-1] ^ f[i])
l.append(0)
for _ in range(q):
	a = int(input())
	print(l[a % (n + 1)])


(n, q) = map(int, input().split(' '))
F = list(map(int, input().split(' ')))
S = [0]
for i in range(n):
	x = S[i] ^ F[i]
	S.append(x)
S.append(0)
for i in range(q):
	k = int(input())
	indx = k % (n + 1)
	print(S[indx])


(n, q) = map(int, input().split())
lst = list(map(int, input().split()))
ans = [lst[0]]
for i in range(1, n):
	ans.append(ans[i - 1] ^ lst[i])
ans.append(0)
for _ in range(q):
	idx = int(input()) % (n + 1) - 1
	print(ans[idx])


(n, q) = list(map(int, input().split()))
l = list(map(int, input().split()))
v = [0 for x in range(n)]
v[0] = l[0]
for j in range(1, n):
	v[j] = v[j - 1] ^ l[j]
for i in range(q):
	k = int(input())
	if k <= n:
		print(v[k - 1])
	else:
		ans = (k - n) % (n + 1) - 1
		if ans == 0:
			print(0)
		elif ans < 0:
			print(v[n - 1])
		else:
			print(v[ans - 1])


(n, q) = map(int, input().split())
f = [*map(int, input().split())]
w = 0
for i in f:
	w ^= i
f += [w]
for i in range(1, len(f)):
	f[i] ^= f[i - 1]
for i in range(q):
	k = int(input()) - 1
	print(f[k % (n + 1)])


nums = list(map(int, input().split()))
arr = list(map(int, input().split()))
count = 0
s = []
for item in arr:
	count = count ^ item
	s.append(count)
for i in range(nums[1]):
	query = int(input())
	if query % (nums[0] + 1) == 0:
		print(0)
	else:
		print(s[query % (nums[0] + 1) - 1])


(n, q) = map(int, input().split())
F = []
S = []
line1 = input().split()
last = 0
for i in range(n):
	F.append(int(line1[i]))
	last = last ^ int(line1[i])
	S.append(last)
S.append(0)
for i in range(q):
	query = int(input())
	pos = (query - 1) % len(S)
	final = S[pos]
	print(final)


(n, q) = input().split()
n = int(n)
q = int(q)
f = [int(fi) for fi in input().split()]
cur = 0
s = [0]
for fi in f:
	cur = cur ^ fi
	s.append(cur)
for i in range(q):
	k = int(input())
	print(s[k % (n + 1)])


(N, Q) = [int(x) for x in input().split()]
F = [int(x) for x in input().split()]
S = [F[0]]
for i in range(1, len(F)):
	S.append(S[-1] ^ F[i])
for _ in range(Q):
	val = int(input()) % (N + 1)
	if not val:
		print(0)
	else:
		print(S[val - 1])


(n, q) = input().split(' ')
n = int(n)
q = int(q)
a = []
pre = 0
b = []
arr = input()
a = list(map(int, arr.split(' ')))
for i in range(0, int(n)):
	pre = pre ^ a[i]
	b.append(pre)
b.append(0)
for i in range(0, int(q)):
	k = int(input())
	k = k - 1
	k = k % (n + 1)
	print(b[k])


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
xor = 0
sl = []
for i in a:
	xor = xor ^ i
	sl.append(xor)
for i in range(q):
	qval = int(input())
	if qval % (n + 1) == 0:
		print(0)
	else:
		print(sl[qval % (n + 1) - 1])


(n, q) = map(int, input().split())
ls = list(map(int, input().split()))
cur = 0
s = [0]
for i in ls:
	cur = cur ^ i
	s.append(cur)
for i in range(q):
	k = int(input())
	print(s[k % (n + 1)])


(n, q) = map(int, input().split(' '))
n_bonacci = list(map(int, input().split(' ')))
arr = []
xor = 0
for val in n_bonacci:
	xor = xor ^ val
	arr.append(xor)
for query in range(q):
	s = int(input())
	if s % (n + 1) == 0:
		print(0)
	else:
		print(arr[s % (n + 1) - 1])


import math
l = [int(x) for x in input().split()]
(n, q) = (l[0], l[1])
f = [int(x) for x in input().split()]
temp = 0
s = []
for each in f:
	temp = temp ^ each
	s.append(temp)
for _ in range(q):
	p = int(input())
	if p % (n + 1) == 0:
		print(0)
	elif p <= n:
		print(s[p - 1])
	else:
		print(s[p % (n + 1) - 1])


import math
from bisect import bisect_left
from code import interact
from heapq import heapify, heappush, heappop
from collections import deque
from pydoc import plain
from re import X
import sys
from math import gcd, sqrt, log10, log2, floor, ceil, sqrt
input = sys.stdin.readline

def il():
	return [int(a) for a in input().strip().split()]

def ip():
	return input().strip()

def ii():
	return int(input())

def ot(in_p, *args, e=' '):
	if type(in_p) == list:
		print(*in_p, end=e)
	if type(in_p) == str or type(in_p) == int:
		print(in_p, end=e)
		for l in args:
			print(l, end=e)
	print()

def a_pwr_n(a, n, mod):
	if n == 1:
		return a % mod
	if n % 2 == 0:
		val = a_pwr_n(a, n // 2, mod)
		return val % mod * val % mod
	else:
		return a % mod * a_pwr_n(a, n - 1, mod) % mod

def rg(*ag):
	if len(ag) == 3:
		return range(ag[0], ag[1], ag[2])
	elif len(ag) == 2:
		return range(ag[0], ag[1])
	elif len(ag) == 1:
		return range(ag[0])
	else:
		raise 'invalid input'

def ispal(i, j, st):
	while i <= j:
		if st[i] == st[j]:
			i = i + 1
			j = j - 1
		else:
			return False
	return True
mod = 1000000000 + 7
dx = [-1, -2, 1, 2, 2, -2, -1, 1]
dy = [2, 1, 2, 1, -1, -1, -2, -2]
l = il()
(n, q) = (l[0], l[1])
l = il()
a = 0
s = []
for i in l:
	a = a ^ i
	s.append(a)
l.append(a)
s.append(0)
s_l = len(s)
for i in range(q):
	k = ii()
	k = k % s_l
	print(s[k - 1])


(n, q) = map(int, input().split())
f = list(map(int, input().split()))
c = f[0]
s = [f[0]]
for i in range(1, n):
	c = c ^ f[i]
	s.append(c)
s.append(0)
for _ in range(q):
	k = int(input())
	print(s[k % (n + 1) - 1])


(n, q) = map(int, input().split())
f1 = list(map(int, input().split()))
f = []
size = n + 1
ans = 0
for i in range(n):
	ans ^= f1[i]
	f.append(ans)
while q:
	k = int(input())
	if k % size == 0:
		print(0)
	else:
		print(f[k % size - 1])
	q -= 1


(n, q) = list(map(lambda x: int(x), input().split()))
a = list(map(lambda x: int(x), input().split()))
xor_a = 0
for i in a:
	xor_a = xor_a ^ i
a.append(xor_a)
prefix = [a[0]]
for i in range(1, len(a)):
	prefix.append(a[i] ^ prefix[i - 1])
for i in range(0, q):
	x = int(input())
	print(prefix[(x - 1) % (n + 1)])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = 0
for i in a:
	f = f ^ i
a.append(f)
d = []
d.append(a[0])
for i in range(1, n + 1):
	d.append(d[-1] ^ a[i])
for i in range(k):
	p = int(input())
	p = p % (n + 1)
	print(d[p - 1])


(n, q) = map(int, input().split())
f = [int(fi) for fi in input().split()]
s = []
sk = 0
for k in range(n):
	sk = sk ^ f[k]
	s.append(sk)
s.append(0)
for _ in range(q):
	k = int(input())
	if k < n:
		print(s[k - 1])
	else:
		print(s[k % (n + 1) - 1])


from sys import stdin
import functools
(n, q) = map(int, stdin.readline().split())
arr = list(map(int, stdin.readline().split()))
d = {1: arr[0]}
ans = arr[0] ^ arr[1]
d[2] = ans
for i in range(2, n):
	ans = ans ^ arr[i]
	d[i + 1] = ans
d[0] = 0
for i in range(q):
	k = int(stdin.readline())
	if k <= n:
		print(d[k])
	else:
		print(d[k % (n + 1)])


(n, q) = map(int, input().split())
f = list(map(int, input().split()))
for j in range(1, n):
	f[j] ^= f[j - 1]
for g in range(q):
	k = int(input())
	tyagibagi = k % (n + 1)
	if tyagibagi == 0:
		print(0)
	else:
		print(f[tyagibagi - 1])


nq = [x for x in list(map(int, input().split(' ')))]
tab = [x for x in list(map(int, input().split(' ')))]
xs = tab[0]
sol = []
sol.append(tab[0])
for i in range(1, nq[0]):
	xs ^= tab[i]
	sol.append(xs)
sol.append(sol[-1] ^ xs)
for i in range(nq[1]):
	q = int(input())
	print(sol[(q - 1) % (nq[0] + 1)])


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
(nb_elem, nb_query) = RMI()
elems = [0] + RMI()
for i in range(1, nb_elem + 1):
	elems[i] ^= elems[i - 1]
nb_elem += 1
for _ in range(nb_query):
	print(elems[RI() % nb_elem])


(n, q) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
xor = a[0]
for i in range(1, len(a)):
	xor = xor ^ a[i]
a.append(xor)
s = [a[0]]
for i in range(1, len(a)):
	s.append(s[-1] ^ a[i])
for I in range(q):
	k = int(input())
	k -= 1
	print(s[k % (n + 1)])


(n, c) = list(map(int, input().split()))
s = [0] * (n + 1)
kp = list(map(int, input().split()))
for i in range(1, n + 1):
	s[i] = s[i - 1] ^ kp[i - 1]
for _ in range(c):
	k = int(input())
	print(s[k % (n + 1)])


(n, Q) = map(int, input().split())
a = [int(x) for x in input().split()]
b = [a[0]]
for i in range(1, n):
	b.append(b[len(b) - 1] ^ a[i])
b.append(0)
n += 1
for q in range(Q):
	k = int(input())
	if k <= n:
		k -= 1
		print(b[k])
	else:
		if k % n == 0:
			k = n
		else:
			k = k % n
		k -= 1
		print(b[k])


a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
c = [0]
d = 0
for e in range(a[0]):
	d = d ^ b[e]
	c.append(d)
for j in range(a[1]):
	e = int(input())
	if e <= a[0]:
		print(c[e])
	else:
		print(c[(e - (a[0] + 1)) % (a[0] + 1)])


(n, q) = map(int, input().split(' '))
f = list(map(int, input().split(' ')))
c = [0]
d = 0
for i in range(n):
	d = d ^ f[i]
	c.append(d)
while q:
	e = int(input())
	if e <= n:
		print(c[e])
	else:
		print(c[(e - (n + 1)) % (n + 1)])
	q = q - 1


(n, q) = map(int, input().split())
f = [int(x) for x in input().split()]
xortab = []
(xor, xor1) = (0, 0)
for i in f:
	xor ^= i
	xortab.append(xor)
xortab.append(0)
for i in range(q):
	k = int(input())
	rem = k % (n + 1)
	print(xortab[rem - 1])


(n, q) = [int(a) for a in input().strip().split()]
F = [int(a) for a in input().strip().split()]
S = [0]
for i in range(n):
	S.append(S[i] ^ F[i])
for _ in range(q):
	k = int(input())
	print(S[k % (n + 1)])


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
t = 1
for tt in range(t):
	(n, q) = map(int, sys.stdin.readline().split(' '))
	a = list(map(int, sys.stdin.readline().split(' ')))
	s = []
	s.append(a[0])
	for i in range(1, n):
		s.append(s[i - 1] ^ a[i])
	for _ in range(q):
		x = int(input())
		x = x % (n + 1)
		if x == 0:
			print(0)
			continue
		print(s[x - 1])
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


(n, q) = map(int, input().strip().split())
flist = list(map(int, input().strip().split()))
num = 0
for ele in flist:
	num = num ^ ele
flist.append(num)
slist = []
num = 0
for ele in flist:
	num = num ^ ele
	slist.append(num)
for _ in range(q):
	ind = int(input())
	ind -= 1
	rem = ind % (n + 1)
	print(slist[rem])
del flist
del slist


(n, q) = map(int, input().split())
arr = list(map(int, input().split()))
prefix_arr = [0] * (n + 1)
for i in range(1, n + 1):
	prefix_arr[i] = prefix_arr[i - 1] ^ arr[i - 1]
for i in range(q):
	pos = int(input())
	print(prefix_arr[pos % (n + 1)])


(n, k) = list(map(int, input().split()))
d = [0] + list(map(int, input().split()))
l = [0]
for i in range(1, n + 1):
	l.append(l[i - 1] ^ d[i])
for q in range(k):
	x = int(input())
	print(l[x % (n + 1)])


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
fin = [a[0]]
for i in range(1, n):
	fin.append(fin[i - 1] ^ a[i])
while q:
	q1 = int(input())
	rem = q1 % (n + 1)
	if rem == 0:
		print(0)
	else:
		print(fin[rem - 1])
	q -= 1


(N, Q) = map(int, input().split())
l = list(map(int, input().split()))
for i in range(N - 1):
	l[i + 1] = l[i + 1] ^ l[i]
for i in range(Q):
	k = int(input())
	k = k % (N + 1)
	if k == 0:
		print(0)
	else:
		print(l[k - 1])


(n, q) = map(int, input().split())
l = list(map(int, input().split()))
f = [0]
for i in range(n):
	y = f[i] ^ l[i]
	f.append(y)
for i in range(q):
	w = int(input())
	t = w % (n + 1)
	print(f[t])


from functools import reduce
(n, q) = map(int, input().split())
l = list(map(int, input().split()))
l.append(reduce(lambda x, y: x ^ y, l))
na = l[:]
for i in range(1, n + 1):
	na[i] = na[i - 1] ^ l[i]
for _ in range(q):
	k = int(input())
	k %= n + 1
	print(na[k - 1])


(N, Q) = input().split()
N = int(N)
Farray = list(map(int, input().split()))
requiredarray = [Farray[0]]
for i in range(1, N):
	requiredarray.append(requiredarray[-1] ^ Farray[i])
requiredarray.append(0)
for j in range(int(Q)):
	q = int(input())
	print(requiredarray[q % (N + 1) - 1])


(n, q) = list(map(int, input().split()))
a = list(map(int, input().split()))
s = [0] * (n + 1)
for i in range(n):
	if i == 0:
		s[i] = a[i]
	else:
		s[i] = s[i - 1] ^ a[i]
s[n] = 0
for _ in range(q):
	k = int(input())
	k -= 1
	k = k % (n + 1)
	print(s[k])


(n, q) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
p = [0] * (n + 1)
for i in range(n):
	if i == 0:
		p[0] = a[0]
	else:
		p[i] = p[i - 1] ^ a[i]
for j in range(q):
	l = int(input())
	x = l % (n + 1)
	print(p[x - 1])


l = list(map(int, input().split()))
n = l[0]
q = l[1]
l = list(map(int, input().split()))
num = 0
for i in range(len(l)):
	num = num ^ l[i]
l.append(num)
s = []
num = 0
for i in range(len(l)):
	num = num ^ l[i]
	s.append(num)
for i in range(q):
	k = int(input())
	k = k % (n + 1)
	k = k - 1
	if k < 0:
		print(s[len(s) - 1])
	else:
		print(s[k])


(n, q) = map(int, input().split(' '))
(ar, xor) = (list(map(int, input().split(' '))), 0)
for x in ar:
	xor ^= x
ar.append(xor)
prefix = [0] * (n + 1)
prefix[0] = ar[0]
for i in range(1, len(prefix)):
	prefix[i] = ar[i] ^ prefix[i - 1]
for i in range(q):
	print(prefix[(int(input()) - 1) % (n + 1)])


l = input().split()
n = int(l[0])
q = int(l[1])
l = input().split()
li = [int(i) for i in l]
xori = 0
si = [0 for i in range(n)]
for i in range(n):
	si[i] = xori
	xori = xori ^ li[i]
si.append(xori)
fi = list(li)
fi.append(xori)
for you in range(q):
	q1 = int(input())
	print(si[q1 % (n + 1)])


(n, q) = map(int, input().split())
f = [int(w) for w in input().split()]
ft = []
ft.append(f[0])
for i in range(1, n):
	temp = ft[i - 1]
	temp = temp ^ f[i]
	ft.append(temp)
ft.append(0)
while q:
	k = int(input())
	index = k % (n + 1) - 1
	print(ft[index])
	q = q - 1


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
sol_arr = [0]
var = 0
for i in range(n):
	var ^= arr[i]
	sol_arr.append(var)
while k > 0:
	x = int(input())
	print(sol_arr[x % (n + 1)])
	k -= 1


(n, q) = map(int, input().split())
a = [int(j) for j in input().split()]
exor = 0
arr = []
for x in range(n):
	exor = exor ^ a[x]
	arr += [exor]
for j in range(q):
	k = int(input())
	if k % (n + 1) == 0:
		print(0)
	else:
		print(arr[k % (n + 1) - 1])


from sys import stdin

def main():
	(n, q) = map(int, stdin.readline().split())
	arr = list(map(int, stdin.readline().split()))
	f = [0, arr[0]]
	xor = arr[0] ^ arr[1]
	f.append(xor)
	for index in range(2, n):
		xor ^= arr[index]
		f.append(xor)
	for query in range(q):
		k = int(stdin.readline())
		if k <= n:
			print(f[k])
		else:
			print(f[k % (n + 1)])
main()


(n, q) = map(int, input().split())
arr = [int(x) for x in input().split()]
x = arr[0]
for i in range(1, len(arr)):
	x = x ^ arr[i]
arr.append(x)
xor = []
xor.append(arr[0])
for i in range(1, len(arr)):
	xor.append(xor[i - 1] ^ arr[i])
xor.insert(0, xor[n])
n += 1
while q != 0:
	q -= 1
	t = int(input())
	print(xor[t % n])


(n, q) = map(int, input().split())
f = list(map(int, input().split()))
s = [f[0]]
for i in range(1, n):
	s.append(f[i] ^ s[i - 1])
s.append(0)
for i in range(q):
	x = int(input())
	x %= n + 1
	print(s[x - 1])


a = [int(s) for s in input().split()]
f = [int(s) for s in input().split()]
s = [0]
curr = 0
for i in range(a[0]):
	curr = curr ^ f[i]
	s.append(curr)
for i in range(a[1]):
	k = int(input())
	print(s[k % (a[0] + 1)])


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
f = [0] * n
for i in range(n):
	if i == 0:
		f[i] = a[i]
	else:
		f[i] = f[i - 1] ^ a[i]
for i in range(q):
	k = int(input())
	x = k % (n + 1)
	if x == 0:
		print(0)
	else:
		print(f[x - 1])


(N, Q) = map(int, input().split())
a = list(map(int, input().split()))
s = []
c = 0
for i in a:
	c ^= i
	s.append(c)
s.append(0)
for i in range(Q):
	print(s[(int(input()) - 1) % len(s)])


(n, q) = map(int, input().split())
f = list(map(int, input().split()))
d = {}
ans = f[0]
for i in range(1, n):
	ans = f[i] ^ ans
f.append(ans)
d[1] = f[0]
for i in range(2, n + 2):
	d[i % (n + 1)] = d[i - 1] ^ f[i - 1]
for _ in range(q):
	k = int(input())
	print(d[k % (n + 1)])


(n, q) = map(int, input().split())
list1 = list(map(int, input().split()))
seq = []
x = 0
for i in list1:
	x ^= i
	seq.append(x)
seq.append(0)
for _ in range(q):
	print(seq[(int(input()) - 1) % len(seq)])


(n, m) = map(int, input().split())
l = [int(i) for i in input().split()]
pr = [0] * (n + 1)
pr = 0
for i in l:
	pr ^= i
l.append(pr)
pre = [0] * (n + 1)
pre[0] = l[0]
for i in range(1, n + 1):
	pre[i] = pre[i - 1] ^ l[i]
for i in range(m):
	x = int(input())
	x -= 1
	print(pre[x % (n + 1)])


(n, q) = list(map(int, input().split()))
s = [0] * (n + 1)
f_seq = list(map(int, input().split()))
for i in range(1, n + 1):
	s[i] = s[i - 1] ^ f_seq[i - 1]
for _ in range(q):
	k = int(input())
	print(s[k % (n + 1)])


(n, q) = map(int, input().split())
f = list(map(int, input().split()))
a = 0
na = [0 for x in range(n + 1)]
na[0] = f[0]
na[n] = 0
for i in range(1, n):
	na[i] = na[i - 1] ^ f[i]
for i in range(q):
	que = int(input())
	print(na[que % (n + 1) - 1])


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
lis = []
xo = 0
for k in a:
	xo = xo ^ k
	lis.append(xo)
for i in range(q):
	ans = 0
	k = int(input())
	z = k % (n + 1)
	if z == 0:
		print(0)
	else:
		print(lis[z - 1])


(N, Q) = map(int, input().split())
F = [0] + list(map(int, input().split()))
x = F[1]
for i in range(2, N + 1):
	x = x ^ F[i]
F.append(x)
S = [0]
S.append(F[1])
for i in range(2, N + 2):
	S.append(F[i] ^ S[i - 1])
for _ in range(Q):
	i = int(input())
	if i % (N + 1) == 0:
		print(0)
	else:
		print(S[i % (N + 1)])


(n, q) = input().strip().split(' ')
(n, q) = (int(n), int(q))
l = list(map(int, input().strip().split(' ')))
temp = l[0]
for i in l[1:]:
	temp ^= i
l.append(temp)
ans = {}
temp = 0
for i in range(n, -1, -1):
	ans[i] = temp ^ l[i]
	temp ^= l[i]
for i in range(q):
	k = int(input())
	print(ans[k % (n + 1)])


(n, q) = map(int, input().split())
f = list(map(int, input().split()))
res = [0] * (n + 1)
for i in range(1, n + 1):
	res[i] = res[i - 1] ^ f[i - 1]
for i in range(q):
	k = int(input())
	print(res[k % (n + 1)])


(N, Q) = map(int, input().split())
l = list(map(int, input().split()))
ans = [0]
sk = 0

def tobinary(a):
	s = ''
	while a > 0:
		s = str(a % 2) + s
		a = a // 2
	return s

def XOR(a, b):
	s1 = tobinary(a)
	s2 = tobinary(b)
	if len(s1) > len(s2):
		s2 = '0' * (len(s1) - len(s2)) + s2
	else:
		s1 = '0' * (len(s2) - len(s1)) + s1
	xor = 0
	for i in range(len(s1)):
		s = 1
		if s1[i] == s2[i]:
			s = 0
		xor += s * 2 ** (len(s1) - 1 - i)
	return xor
for i in range(N):
	sk = XOR(sk, l[i])
	ans.append(sk)
for i in range(Q):
	k = int(input())
	k = k % (N + 1)
	print(ans[k])


(a, b) = map(int, input().split())
A = list(map(int, input().split()))
B = []
xor = 0
for i in range(a):
	xor ^= A[i]
	B.append(xor)
for _ in range(b):
	t = int(input())
	if t % (a + 1) == 0:
		print(0)
	else:
		hade = t % (a + 1)
		hade -= 1
		print(B[hade])


from math import *
from collections import *
from itertools import *
from functools import *
from bisect import *
from heapq import *
from operator import *
from sys import *
setrecursionlimit(100000000)
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
l.append(reduce(xor, l))
l = list(accumulate(l, xor))
for _ in range(k):
	v = int(input())
	print(l[(v - 1) % len(l)])


ans = []
(n, q) = map(int, input().split())
arr = [int(x) for x in input().split()]
pre = 0
for i in range(n):
	pre = pre ^ arr[i]
	ans.append(pre)
ans.append(0)
for _ in range(q):
	que = int(input())
	print(ans[que % (n + 1) - 1])


(n, q) = map(int, input().split())
f = list(map(int, input().split()))
arr = [f[0]]
for i in range(1, n):
	arr.append(f[i] ^ arr[i - 1])
arr.append(0)
n = n + 1
for i in range(q):
	k = int(input())
	print(arr[(k - 1) % n])


(n, q) = map(int, input().split())
arr = [int(n) for n in input().split()]
x = arr[0]
arr1 = []
arr1.append(x)
for i in range(1, n):
	x = x ^ arr[i]
	arr1.append(x)
arr1.append(0)
while q:
	q = q - 1
	x = int(input())
	r = x % (n + 1)
	print(arr1[r - 1])


(n, q) = map(int, input().split())
f = list(map(int, input().split()))
record = []
r = 0
for i in range(n):
	record.append(f[i])
	r = r ^ f[i]
record.append(r)
s = [record[0]]
for i in range(1, n + 1):
	s.append(s[i - 1] ^ record[i])
for i in range(q):
	k = int(input())
	temp = k % (n + 1)
	print(s[temp - 1])


(n, q) = map(int, input().split())
l = list(map(int, input().split()))
t = []
for i in range(q):
	t.append(int(input()))
k = 0
l1 = []
for i in l:
	k ^= i
	l1.append(k)
l1 += [0]
lenl = len(l1)
for i in t:
	print(l1[(i - 1) % lenl])


(n, q) = map(int, input().split())
nli = [0] + list(map(int, input().split()))
d = [0]
for i in range(1, n + 1):
	d.append(d[i - 1] ^ nli[i])
for j in range(q):
	qi = int(input())
	print(d[qi % (n + 1)])


(N, Q) = map(int, input().split())
arr = list(map(int, input().split()))
temp = arr[0]
f = [arr[0]]
for num in arr[1:]:
	temp ^= num
	f.append(temp)
for i in range(Q):
	q = int(input())
	s = q % (N + 1)
	ans = 0
	if s >= 1:
		ans = f[s - 1]
	print(ans)