Declare a 2-dimensional array, $\textbf{arr}$, of $n$ empty arrays.  All arrays are zero indexed. 

Declare an integer, $lastAnswer$, and initialize it to $\text{\mbox{0}}$. 

There are $2$ types of queries, given as an array of strings for you to parse:  

Query: 1 x y

Let $i dx = ((x\oplus lastAnswer)\%n)$.
Append the integer $y$ to $ar r[id x]$.
Query: 2 x y

Let $idx = ((x\oplus lastAnswer)\%n)$.
Assign the value $arr[idx][y\% size(arr[idx])]$ to $lastAnswer$.   
Store the new value of $lastAnswer$ to an answers array.

Note: $\oplus$ is the bitwise XOR operation, which corresponds to the ^ operator in most languages. Learn more about it on Wikipedia. $\%$ is the modulo operator. 

Finally, size(arr[idx]) is the number of elements in arr[idx]  

Function Description  

Complete the dynamicArray function below.  

dynamicArray has the following parameters: 

- int n: the number of empty arrays to initialize in $\textbf{arr}$ 

- string queries[q]: query strings that contain 3 space-separated integers 

Returns  

int[]:  the results of each type 2 query in the order they are presented  

Input Format

The first line contains two space-separated integers, $n$, the size of $\textbf{arr}$ to create, and $\textit{q}$, the number of queries, respectively. 

Each of the $\textit{q}$ subsequent lines contains a query string, $\textit{queries}[i]$.

Constraints

$1\leq n,q\leq10^5$
$0\leq x,y\leq10^9$
It is guaranteed that query type $2$ will never query an empty array or index.

Sample Input
2 5
1 0 5
1 1 7
1 0 3
2 1 0
2 1 1

Sample Output
7
3

Explanation

Initial Values: 

$n=2$ 

$lastAnswer=0$ 

$ar r[0]$ = [ ] 

$ar r[1]$ = [ ]  

Query 0: Append $5$ to $arr[ (0\oplus 0) \% 2 )]=arr[0]$. 

$last Answer=0$ 

$ar r[0]$ = [5] 

$ar r[1]$ = [ ]      

Query 1: Append $7$ to $arr[(\left(1\oplus0\right)\%2\right)]=arr[1]$. 

$ar r[0]$ = [5] 

$ar r[1]$ = [7]   

Query 2: Append $3$ to $arr[ (0\oplus 0) \% 2 )]=arr[0]$. 

$lastAnswer=0$ 

$ar r[0]$ = [5, 3] 

$ar r[1]$ = [7]    

Query 3: Assign the value at index $0$ of $arr[ (1 \oplus 0) \% 2 )]=arr[1]$ to $lastAnswer$, print $lastAnswer$. 

$lastAnswer=7$ 

$ar r[0]$ = [5, 3] 

$ar r[1]$ = [7]   

7

Query 4: Assign the value at index $1$ of $arr[(1\oplus7)\%2)]=arr[0]$ to $lastAnswer$, print $lastAnswer$. 

$lastAnswer=3$ 

$ar r[0]$ = [5, 3] 

$ar r[1]$ = [7]   

3

Difficulty: EASY
Tags: Data structures
Skill types: Data structures

Starter code:

Solutions:
(n, q) = map(int, input().split())
l = [[] for _ in range(n)]
latsans = 0
for _ in range(q):
	(a, x, y) = map(int, input().split())
	if a == 1:
		l[(x ^ latsans) % n].append(y)
	else:
		t = (x ^ latsans) % n
		latsans = l[t][y % len(l[t])]
		print(latsans)


(N, Q) = map(int, input().split())
lastans = 0
Seqs = [[] for _ in range(N)]
for _ in range(Q):
	(t, x, y) = map(int, input().split())
	if t == 1:
		Seqs[(x ^ lastans) % N].append(y)
	elif t == 2:
		arr = Seqs[(x ^ lastans) % N]
		val = arr[y % len(arr)]
		print(val)
		lastans = val


(n, q) = [int(i) for i in input().split()]
ar = []
for i in range(n):
	ar.append([])
lastans = 0
while q:
	(t, x, y) = [int(i) for i in input().split()]
	if t == 1:
		ar[(x ^ lastans) % n].append(y)
	else:
		print(ar[(x ^ lastans) % n][y % len(ar[(x ^ lastans) % n])])
		lastans = ar[(x ^ lastans) % n][y % len(ar[(x ^ lastans) % n])]
	q -= 1


(n, q) = [int(i) for i in input().split()]
matrix = [[] for i in range(n)]
lastans = 0
for _ in range(q):
	(a, b, c) = [int(i) for i in input().split()]
	if a == 1:
		matrix[(b ^ lastans) % n].append(c)
	else:
		temp = (b ^ lastans) % n
		size = len(matrix[temp])
		lastans = matrix[temp][c % size]
		print(lastans)


(n, q) = [int(x) for x in input().split()]
a = []
for i in range(n):
	a.append([])
las = 0
for t in range(q):
	inp = [int(x) for x in input().split()]
	if inp[0] == 1:
		a[(inp[1] ^ las) % n].append(inp[2])
	else:
		print(a[(inp[1] ^ las) % n][inp[2] % len(a[(inp[1] ^ las) % n])])
		las = a[(inp[1] ^ las) % n][inp[2] % len(a[(inp[1] ^ las) % n])]


(n, q) = map(int, input().split())
l = [[] for _ in range(n)]
la = 0
for _ in range(q):
	(t, x, y) = map(int, input().split())
	if t == 1:
		l[(x ^ la) % n].append(y)
	elif t == 2:
		la = l[(x ^ la) % n][y % len(l[(x ^ la) % n])]
		print(la)
	else:
		raise Exception('WHAT THE HELL IS TYPE ' + t + '??!!')


import sys
list = []
for line in sys.stdin:
	list.append(line.strip('\n'))
line = list[0].split()
n = int(line[0])
q = int(line[1])
lists = []
lastans = 0
for i in range(0, n):
	lists.append([])
for i in range(1, q + 1):
	line = list[i].split()
	if line[0] == '1':
		lists[(int(line[1]) ^ lastans) % n].append(int(line[2]))
	if line[0] == '2':
		size = len(lists[(int(line[1]) ^ lastans) % n])
		lastans = lists[(int(line[1]) ^ lastans) % n][int(line[2]) % size]
		print(lastans)


f = input().split()
n = int(f[0])
q = int(f[1])
ar = []
lastans = 0
for i in range(n):
	ar.append([])
for i in range(q):
	d = [int(x) for x in input().split()]
	if d[0] == 1:
		ar[(d[1] ^ lastans) % n].append(d[2])
	else:
		sz = len(ar[(d[1] ^ lastans) % n])
		lastans = ar[(d[1] ^ lastans) % n][d[2] % sz]
		print(lastans)


(n, q) = map(int, input().split())
lastans = 0
seqs = [[] for _ in range(0, n)]
for _ in range(0, q):
	(c, x, y) = map(int, input().split())
	seqIx = (x ^ lastans) % n
	if c == 1:
		seqs[seqIx].append(y)
	else:
		seq = seqs[seqIx]
		lastans = seq[y % len(seq)]
		print(lastans)


import sys

def insert(x, N, lastans, y, arr_of_seq):
	seq_id = (x ^ lastans) % N
	arr_of_seq[seq_id].append(y)
	return arr_of_seq

def pr(x, y, N, lastans, arr_of_seq):
	seq_id = (x ^ lastans) % N
	value_ind = y % len(arr_of_seq[seq_id])
	print(arr_of_seq[seq_id][value_ind])
	return arr_of_seq[seq_id][value_ind]
inp = [i for i in input().strip().split(' ')]
N = int(inp[0])
Q = int(inp[1])
lastans = 0
arr_of_seq = []
for i in range(N):
	arr_of_seq.append([])
for i in range(Q):
	query = [i for i in input().strip().split(' ')]
	x = int(query[1])
	y = int(query[2])
	if int(query[0]) == 1:
		insert(x, N, lastans, y, arr_of_seq)
	else:
		lastans = pr(x, y, N, lastans, arr_of_seq)


(n, q) = map(int, input().split())
seq = []
for i in range(0, n):
	seq.append([])
lastans = 0
for i in range(0, q):
	(c, x, y) = map(int, input().split())
	t = (x ^ lastans) % n
	if c == 1:
		seq[t].append(y)
	else:
		lastans = seq[t][y % len(seq[t])]
		print(lastans)


(n, q) = [int(temp) for temp in input().strip().split()]
a = [list() for _ in range(n)]
lastans = 0
for _ in range(q):
	(o, x, y) = [int(temp) for temp in input().strip().split()]
	if o == 1:
		a[(x ^ lastans) % n].append(y)
	elif o == 2:
		print(a[(x ^ lastans) % n][y % len(a[(x ^ lastans) % n])])
		lastans = a[(x ^ lastans) % n][y % len(a[(x ^ lastans) % n])]


(n, q) = map(int, input().strip().split(' '))
lastans = 0
arrs = tuple(([] for i in range(n)))
for qi in range(q):
	(com, x, y) = map(int, input().strip().split())
	if com == 1:
		arrs[(x ^ lastans) % n].append(y)
	else:
		arr = arrs[(x ^ lastans) % n]
		val = arr[y % len(arr)]
		print(val)
		lastans = val


(n, q) = list(map(int, input().split()))
arr = [[] for i in range(n)]
lastans = 0
for i in range(q):
	(order, x, y) = list(map(int, input().split()))
	if order == 1:
		arr[(x ^ lastans) % n].append(y)
	else:
		a = arr[(x ^ lastans) % n]
		print(a[y % len(a)])
		lastans = a[y % len(a)]


(n, q) = map(int, input().split())
lastans = 0
data = [[] for _ in range(n)]
for _ in range(q):
	(a, x, y) = map(int, input().split())
	i = (x ^ lastans) % n
	if a == 1:
		data[i].append(y)
	elif a == 2:
		lastans = data[i][y % len(data[i])]
		print(lastans)


import sys
data = input().strip().split(' ')
(N, Q) = (int(data[0]), int(data[1]))
lastans = 0
lists = [[] for x in range(N)]
for i in range(Q):
	arr = input().strip().split(' ')
	n = int(arr[0])
	x = int(arr[1])
	y = int(arr[2])
	list_index = (x ^ lastans) % N
	if n == 1:
		lists[list_index].append(y)
	if n == 2:
		size = len(lists[list_index])
		lastans = lists[list_index][y % size]
		print(lastans, end='\n')


nq = input().strip().split(' ')
n = int(nq[0])
q = int(nq[1])
lastans = 0
seq = [[] for i in range(n)]
for i in range(q):
	query = input().strip().split(' ')
	x = int(query[1])
	y = int(query[2])
	if query[0] == '1':
		seq[(x ^ lastans) % n].append(y)
	else:
		p = seq[(x ^ lastans) % n][y % len(seq[(x ^ lastans) % n])]
		lastans = p
		print(p)


(n, q) = map(int, input().split())
sequences = [[] for x in range(n)]
lastans = 0
for i in range(q):
	(command, x, y) = map(int, input().split())
	sequence_index = (x ^ lastans) % n
	sequence = sequences[sequence_index]
	if command == 1:
		sequence.append(y)
	elif command == 2:
		lastans = sequence[y % len(sequence)]
		print(lastans)


def inputIntList():
	return [int(x) for x in input().strip().split()]
(n, q) = inputIntList()
sequences = [[]] * n
lastans = 0
for i in range(q):
	(t, x, y) = inputIntList()
	if t == 1:
		sequences[(x ^ lastans) % n] = sequences[(x ^ lastans) % n] + [y]
	if t == 2:
		size = len(sequences[(x ^ lastans) % n])
		value = sequences[(x ^ lastans) % n][y % size]
		print(value)
		lastans = value


[N, Q] = [int(x) for x in input().split(' ')]
lastans = 0
n = []
for i in range(0, N):
	n.append([])
for i in range(0, Q):
	[t, x, y] = [int(x) for x in input().split(' ')]
	sequence = (x ^ lastans) % N
	if t == 1:
		n[sequence].append(y)
	elif t == 2:
		spot = y % len(n[sequence])
		lastans = n[sequence][spot]
		print(n[sequence][spot])
	else:
		print('error t out of range')


lastans = 0
[N, Q] = [int(x) for x in input().split()]
sequences = []
for _ in range(N):
	sequences.append([])
for _ in range(Q):
	[q, x, y] = [int(x) for x in input().split()]
	if q == 1:
		sequences[(x ^ lastans) % N].append(y)
	else:
		sequence = sequences[(x ^ lastans) % N]
		value = sequence[y % len(sequence)]
		print(value)
		lastans = value


inp = input().split(' ')
N = int(inp[0])
Q = int(inp[1])
lastans = 0
sequences = []
for i in range(N):
	sequences.append([])
for i in range(Q):
	query = input().split(' ')
	num = int(query[0])
	x = int(query[1])
	y = int(query[2])
	if num == 1:
		sequences[(x ^ lastans) % N].append(y)
	else:
		seqToPrint = sequences[(x ^ lastans) % N]
		valToPrint = seqToPrint[y % len(seqToPrint)]
		print(valToPrint)
		lastans = valToPrint


(n, q) = input().strip().split(' ')
(n, q) = (int(n), int(q))
seq = []
for i in range(n):
	seq.append([])
lastans = 0
for i in range(q):
	arr = [int(arr_temp) for arr_temp in input().strip().split(' ')]
	curSeq = seq[(arr[1] ^ lastans) % n]
	if arr[0] == 1:
		curSeq.append(arr[2])
	elif arr[0] == 2:
		print(curSeq[arr[2] % len(curSeq)])
		lastans = curSeq[arr[2] % len(curSeq)]


[N, Q] = [int(_) for _ in input().strip().split()]
seq = [[]]
lastans = 0
for _ in range(N - 1):
	seq.append([])
for q in range(Q):
	[t, x, y] = [int(_) for _ in input().strip().split()]
	s = (x ^ lastans) % N
	if t == 1:
		seq[s].append(y)
	elif t == 2:
		index = y % len(seq[s])
		lastans = seq[s][index]
		print(lastans)
	else:
		print('ERROR')


import sys
(n_seq, q) = [int(e) for e in input().split()]
print('{} {}'.format(n_seq, q), file=sys.stderr)
seq = []
last_ans = 0
for _ in range(n_seq):
	seq.append([])
for _ in range(q):
	(c, x, y) = [int(e) for e in input().split()]
	if c == 1:
		print('inset {} at seq {}'.format(y, (x ^ last_ans) % n_seq), file=sys.stderr)
		seq[(x ^ last_ans) % n_seq].append(y)
	elif c == 2:
		print('print {} at seq {}'.format(seq[(x ^ last_ans) % n_seq][y % len(seq[(x ^ last_ans) % n_seq])], (x ^ last_ans) % n_seq), file=sys.stderr)
		temp = seq[(x ^ last_ans) % n_seq][y % len(seq[(x ^ last_ans) % n_seq])]
		print(temp)
		last_ans = temp
	else:
		pass


(n, queries) = (int(x) for x in input().split())
seqs = [[] for x in range(n)]
lastans = 0

def one(x, y, lastans):
	i = (x ^ lastans) % n
	seqs[i].append(y)

def two(x, y, lastans):
	i = (x ^ lastans) % n
	j = y % len(seqs[i])
	return seqs[i][j]
for query in range(queries):
	q = [int(x) for x in input().split()]
	if q[0] == 1:
		one(q[1], q[2], lastans)
	elif q[0] == 2:
		lastans = two(q[1], q[2], lastans)
		print(lastans)


(N, Q) = input().strip().split(' ')
N = int(N)
Q = int(Q)
lastans = 0
sequences = [[] for _ in range(N)]
for _ in range(Q):
	(flag, x, y) = input().strip().split(' ')
	x = int(x)
	y = int(y)
	index = (x ^ lastans) % N
	if flag == '1':
		sequences[index].append(y)
	else:
		sub_index = y % len(sequences[index])
		lastans = sequences[index][sub_index]
		print(lastans)


(n, q) = [int(s) for s in input().strip().split()]
lastans = 0
arrs = []
for i in range(n):
	arrs.append([])
for query in range(q):
	(type, x, y) = [int(s) for s in input().strip().split()]
	if type == 1:
		i = (x ^ lastans) % n
		arrs[i].append(y)
	elif type == 2:
		i = (x ^ lastans) % n
		length = len(arrs[i])
		lastans = arrs[i][y % length]
		print(lastans)


import sys
(N, Q) = input().strip().split(' ')
(N, Q) = (int(N), int(Q))
l = []
lastans = 0
for i in range(N):
	l.append([])
for i in range(Q):
	(qtype, x, y) = input().strip().split(' ')
	(qtype, x, y) = (int(qtype), int(x), int(y))
	j = (x ^ lastans) % N
	if qtype == 1:
		if j < len(l):
			l[j].append(y)
	elif qtype == 2:
		lastans = l[j][y % len(l[j])]
		print(lastans)


(n, q) = [int(x) for x in input().split()]
arr = [[] for _ in range(n)]
lastans = 0
for _ in range(q):
	(q_id, x, y) = [int(x) for x in input().split()]
	sq = (x ^ lastans) % n
	if q_id == 1:
		arr[sq].append(y)
	elif q_id == 2:
		value = arr[sq][y % len(arr[sq])]
		print(value)
		lastans = value


(N, Q) = [int(x) for x in input().split()]
array = [[] for i in range(N)]
lastans = 0
queries = [(int(i[0]), int(i[1]), int(i[2])) for i in [input().split() for x in range(Q)]]
for q in queries:
	if q[0] == 1:
		array[(q[1] ^ lastans) % N].append(q[2])
	elif q[0] == 2:
		res = array[(q[1] ^ lastans) % N][q[2] % len(array[(q[1] ^ lastans) % N])]
		print(res)
		lastans = res


import sys
lastans = 0
(N, Q) = (int(s) for s in input().strip().split(' '))
sequences = [[] for a in range(N)]
for a in range(Q):
	(rule, x, y) = (int(s) for s in input().strip().split(' '))
	element = (x ^ lastans) % N
	if rule == 1:
		sequences[element].append(y)
	elif rule == 2:
		lastans = sequences[element][y % len(sequences[element])]
		print(lastans)


from operator import xor
from collections import defaultdict
myDic = defaultdict(list)
(n, q) = input().strip().split()
arr = []
lastans = 0
seq = list()
for arr_i in range(int(q)):
	arr_t = [int(arr_temp) for arr_temp in input().strip().split(' ')]
	arr.append(arr_t)
for i in range(int(q)):
	if arr[i][0] == 1:
		myDic[xor(arr[i][1], lastans) % int(n)].append(arr[i][2])
	else:
		print(myDic[xor(arr[i][1], lastans) % int(n)][arr[i][2] % len(myDic[xor(arr[i][1], lastans) % int(n)])])
		lastans = myDic[xor(arr[i][1], lastans) % int(n)][arr[i][2] % len(myDic[xor(arr[i][1], lastans) % int(n)])]


from collections import defaultdict
(N, Q) = (int(x) for x in input().split())
seqs = defaultdict(list)
lastans = 0
for _ in range(Q):
	(t, x, y) = (int(x) for x in input().split())
	n = (x ^ lastans) % N
	seq = seqs[n]
	if t == 1:
		seq.append(y)
	else:
		lastans = seq[y % len(seq)]
		print(lastans)


input_params = input().strip().split(' ')
n_seq = int(input_params[0])
n_queries = int(input_params[1])
last_ans = 0
sequences = []
for idx in range(n_seq):
	sequences.append([])
for idx in range(n_queries):
	query = input().strip().split(' ')
	x = int(query[1])
	y = int(query[2])
	seq_idx = (x ^ last_ans) % n_seq
	if int(query[0]) == 1:
		sequences[seq_idx].append(y)
	elif int(query[0]) == 2:
		pos = y % len(sequences[seq_idx])
		result = sequences[seq_idx][pos]
		print(result)
		last_ans = result


import sys
a = [int(s) for s in input().split(' ')]
N = a[0]
m = a[1]
arr = [[] for i in range(N)]
lastans = 0
for i in range(m):
	a = [int(s) for s in input().split(' ')]
	if a[0] == 1:
		arr[(a[1] ^ lastans) % N].append(a[2])
	else:
		x = len(arr[(a[1] ^ lastans) % N])
		y = arr[(a[1] ^ lastans) % N][a[2] % x]
		print(y)
		lastans = y


import sys
lastans = 0
(n, k) = input().strip().split(' ')
(n, k) = [int(n), int(k)]
sequences = [[] for i in range(n)]
for i in range(k):
	(query, x, y) = input().strip().split(' ')
	(query, x, y) = [int(query), int(x), int(y)]
	j = (x ^ lastans) % n
	if query == 1:
		sequences[j].append(y)
	elif query == 2:
		k = y % len(sequences[j])
		lastans = sequences[j][k]
		print(lastans)


import sys
line1 = input().strip().split(' ')
n = int(line1[0])
q = int(line1[1])
lastans = 0
arr = {}
for i in range(q):
	inst = input().strip().split(' ')
	x = int(inst[1])
	y = int(inst[2])
	pos = (x ^ lastans) % n
	if inst[0] == '1':
		seq = arr.get(pos, [])
		seq.append(y)
		arr[pos] = seq
	elif inst[0] == '2':
		seq = arr[pos]
		size = len(seq)
		ret = y % size
		print(seq[ret])
		lastans = seq[ret]


(N, queries) = [int(n) for n in input().split()]
lastans = 0
dic = {}
for i in range(0, N):
	dic[i] = []
for i in range(0, queries):
	(a, x, y) = [int(n) for n in input().split()]
	if a == 1:
		seq = (x ^ lastans) % N
		dic[seq].append(y)
	elif a == 2:
		seq = (x ^ lastans) % N
		lastans = dic[seq][y % len(dic[seq])]
		print(lastans)


(n, q) = map(int, input().split())
seq = [[] for i in range(n)]
lastans = 0
for _ in range(q):
	(op, x, y) = map(int, input().split())
	if op == 1:
		seq[(x ^ lastans) % n].append(y)
	else:
		lastans = seq[(x ^ lastans) % n][y % len(seq[(x ^ lastans) % n])]
		print(lastans)


lastans = 0
arr = []
seq = []
(n, q) = input().split(' ')
n = int(n)
q = int(q)
for i in range(n):
	seq.append([])
for arr_i in range(q):
	arr_t = [int(arr_temp) for arr_temp in input().strip().split(' ')]
	arr.append(arr_t)
for i in range(q):
	if arr[i][0] == 1:
		seq[(arr[i][1] ^ lastans) % n].append(arr[i][2])
	if arr[i][0] == 2:
		temp = seq[(arr[i][1] ^ lastans) % n][arr[i][2] % len(seq[(arr[i][1] ^ lastans) % n])]
		lastans = temp
		print(temp)


(n, q) = input().split(' ')
(n, q) = (int(n), int(q))
seqs = [[] for sequence in range(n)]
lastans = 0
for line in range(q):
	(type, x, y) = input().split(' ')
	(type, x, y) = (int(type), int(x), int(y))
	if type == 1:
		seqs[(x ^ lastans) % n].append(y)
	elif type == 2:
		seq = seqs[(x ^ lastans) % n]
		value = seq[y % len(seq)]
		print(value)
		lastans = value


x = input().strip().split(' ')
n = int(x[0])
h = int(x[1])
grid = []
last = 0
for itr in range(h):
	grid_t = input().strip().split(' ')
	grid.append(grid_t)
temp = [None] * n
for itr in grid:
	if itr[0] == '1':
		index = (int(itr[1]) ^ last) % n
		if temp[index] == None:
			temp[index] = [int(itr[2])]
		else:
			temp[index].append(int(itr[2]))
	else:
		te = (int(itr[1]) ^ last) % n
		last = temp[te][int(itr[2]) % len(temp[te])]
		print(last)


import sys

def main():
	metadata = input().split(' ')
	n = int(metadata[0])
	querries = int(metadata[1])
	seqs = []
	for i in range(0, n):
		seqs.append([])
	lastans = 0
	for i in range(0, querries):
		query = input().split(' ')
		if len(query) != 3:
			print('malformed query found: ' + query)
			return
		cmd = int(query[0])
		x = int(query[1])
		y = int(query[2])
		index = (x ^ lastans) % n
		if cmd == 1:
			seqs[index].append(y)
		elif cmd == 2:
			lastans = seqs[index][y % len(seqs[index])]
			print(str(lastans))
		else:
			print('unknown query command: ' + str(cmd))
			return
main()


(n, q) = [int(x) for x in input().split()]
sequences = [[] for i in range(n)]
lastans = 0
for i in range(q):
	(t, x, y) = [int(z) for z in input().split()]
	index = (x ^ lastans) % n
	seq = sequences[index]
	if t == 1:
		seq.append(y)
	else:
		size = len(seq)
		result = seq[y % size]
		print(result)
		lastans = result


def unpack_input():
	return tuple((int(x) for x in input().split(' ')))
lastans = 0
sequences = {}
(N, Q) = unpack_input()
for _ in range(Q):
	(q, x, y) = unpack_input()
	if q == 1:
		insert_index = (x ^ lastans) % N
		if insert_index not in sequences:
			sequences[insert_index] = []
		sequences[insert_index].append(y)
	elif q == 2:
		sequence_index = (x ^ lastans) % N
		element_index = y % len(sequences[sequence_index])
		new_lastans = sequences[sequence_index][element_index]
		print(new_lastans)
		lastans = new_lastans


s = input()
s = s.split(' ')
lastans = 0
numSequences = int(s[0])
numQuery = int(s[1])
dynamicArray = []
for i in range(numSequences):
	s = []
	dynamicArray.append(s)
for i in range(numQuery):
	s = input()
	s = s.split(' ')
	case = int(s[0])
	x = int(s[1])
	y = int(s[2])
	insertIndex = (x ^ lastans) % numSequences
	if case == 1:
		dynamicArray[insertIndex].append(y)
	elif case == 2:
		printIndex = y % len(dynamicArray[insertIndex])
		lastans = dynamicArray[insertIndex][printIndex]
		print(dynamicArray[insertIndex][printIndex])


(N, Q) = [int(x) for x in input().split()]
seq = [[] for _ in range(N)]
lastAns = 0
for _ in range(Q):
	(q, x, y) = [int(x) for x in input().split()]
	ind = (lastAns ^ x) % N
	if q == 1:
		seq[ind].append(y)
	else:
		lastAns = seq[ind][y % len(seq[ind])]
		print(lastAns)


def q1(x, y):
	ndx = (x ^ lastans) % N
	A[ndx].append(y)

def q2(x, y):
	ndx1 = (x ^ lastans) % N
	ndx2 = y % len(A[ndx1])
	print(A[ndx1][ndx2])
	return A[ndx1][ndx2]
[N, Q] = list(map(int, input().split(' ')))
A = [[] for i in range(0, N)]
lastans = 0
for i in range(0, Q):
	[q, x, y] = list(map(int, input().split(' ')))
	if q == 1:
		q1(x, y)
	else:
		lastans = q2(x, y)


from collections import defaultdict
seqs = defaultdict(list)
lastans = 0
(N, queries) = (int(x) for x in input().split())
for xxx in range(queries):
	(a, x, y) = (int(x) for x in input().split())
	i = (x ^ lastans) % N
	if a == 1:
		seqs[i].append(y)
	else:
		lastans = seqs[i][y % len(seqs[i])]
		print(lastans)


(N, Q) = [int(_) for _ in input().strip().split(' ')]
la = 0
ars = [[] for _ in range(N)]
for _ in range(Q):
	(o, x, y) = [int(__) for __ in input().strip().split(' ')]
	if o == 1:
		ars[(x ^ la) % N].append(y)
	else:
		i = (x ^ la) % N
		la = ars[i][y % len(ars[i])]
		print(la)


l = [int(x) for x in input().split()]
n = l[0]
q = l[1]
lastans = 0
d = {}
i = 0
while q > 0:
	q = q - 1
	l = [int(x) for x in input().split()]
	x = l[1]
	y = l[2]
	seq = int((x ^ lastans) % n)
	if l[0] == 1:
		if seq not in d:
			d[seq] = []
		d[seq].append(y)
	else:
		i = y % len(d[seq])
		print(d[seq][i])
		lastans = d[seq][i]


import sys

def read_line():
	return [int(i) for i in sys.stdin.readline().split()]

def get_sequence_idx(x, last_ans, N):
	return (x ^ last_ans) % N

def action_one(sequences, x, y, last_ans, N):
	i_sequence = get_sequence_idx(x, last_ans, N)
	sequences[i_sequence].append(y)

def action_two(sequences, x, y, last_ans, N):
	i_sequence = get_sequence_idx(x, last_ans, N)
	size = len(sequences[i_sequence])
	i_elem = y % size
	elem = sequences[i_sequence][i_elem]
	print(elem)
	return elem

def main():
	(N, Q) = read_line()
	sequences = [[] for _ in range(N)]
	last_ans = 0
	for q in range(Q):
		(t, x, y) = read_line()
		if t == 1:
			action_one(sequences, x, y, last_ans, N)
		elif t == 2:
			last_ans = action_two(sequences, x, y, last_ans, N)
		else:
			raise ValueError('Invalid t != 1, 2')
main()


(n, q) = map(int, input().split())
l = list()
v = 0
for _ in range(n):
	l.append([])
for _ in range(q):
	(qno, x, y) = map(int, input().split())
	if qno == 1:
		l[(x ^ v) % n].append(y)
	else:
		tmp = (x ^ v) % n
		size = len(l[tmp])
		v = l[tmp][y % size]
		print(v)


(n, m) = map(int, input().split())
l = [[] for i in range(n)]
lastAnswer = 0
for i in range(m):
	(why, x, y) = map(int, input().split())
	f = (x ^ lastAnswer) % n
	if why == 1:
		l[f].append(y)
	else:
		v = len(l[f])
		lastAnswer = l[f][y % v]
		print(lastAnswer)


(n, q) = map(int, input().split())
lst = []
for i in range(n):
	lst.append([])
lastans = 0
for _ in range(q):
	(d, x, y) = map(int, input().split())
	if d == 1:
		lst[(x ^ lastans) % n].append(y)
	else:
		k = lst[(x ^ lastans) % n][y % len(lst[(x ^ lastans) % n])]
		print(k)
		lastans = k


(n, q) = map(int, input().strip().split(' '))
assert n >= 1, ' N should be > 1'
assert pow(10, 5) >= q, 'Q should be > %r' % pow(10, 5)
da = [[] for _ in range(n)]
lastans = 0
for _ in range(q):
	(qt, x, y) = map(int, input().strip().split(' '))
	assert 0 <= x <= pow(10, 9), ' x should be >=0 and <=%r' % pow(10, 9)
	assert 0 <= y <= pow(10, 9), ' y should be >=0 and <=%r' % pow(10, 9)
	i = (x ^ lastans) % n
	if qt == 1:
		da[i].append(y)
	elif qt == 2:
		size = len(da[i])
		lastans = da[i][y % size]
		print(lastans)


import sys
arr = [int(arr_temp) for arr_temp in input().strip().split(' ')]
lastans = 0
N = arr[0]
Q = arr[1]
sequences = [[] for x in range(N)]
for i in range(Q):
	arr = [int(arr_temp) for arr_temp in input().strip().split(' ')]
	type = arr[0]
	x = arr[1]
	y = arr[2]
	sequence = (x ^ lastans) % N
	if type == 1:
		sequences[sequence].append(y)
	elif type == 2:
		size = len(sequences[sequence])
		element = y % size
		ans = sequences[sequence][element]
		print(ans)
		lastans = ans


lastans = 0
[N, Q] = map(int, input().split(sep=' '))
arr = [[] for i in range(0, N)]
for i in range(0, Q):
	[flag, x, y] = map(int, input().split(sep=' '))
	index = (x ^ lastans) % N
	if flag == 1:
		arr[index].append(y)
	else:
		ele_idx = y % len(arr[index])
		lastans = arr[index][ele_idx]
		print(lastans)


(N, Q) = [int(i) for i in input().split()]
A = [[] for i in range(N)]
L = 0
while Q != 0:
	(C, X, Y) = [int(i) for i in input().split()]
	if C == 1:
		A[(X ^ L) % N].append(Y)
	else:
		S = A[(X ^ L) % N]
		L = S[Y % len(S)]
		print(L)
	Q -= 1


(N, Q) = [int(x) for x in input().strip().split(' ')]
seqs = [[] for x in range(N + 1)]
queries = []
lastans = 0
for i in range(Q):
	queries.append([int(x) for x in input().strip().split(' ')])
for query in queries:
	(t, x, y) = query
	if t == 1:
		seqs[(x ^ lastans) % N].append(y)
	elif t == 2:
		length = len(seqs[(x ^ lastans) % N])
		lastans = seqs[(x ^ lastans) % N][y % length]
		print(lastans)


(N, Q) = map(int, input().split())
lastans = 0
seqs = [[] for _ in range(N)]
while Q > 0:
	Q -= 1
	(op, x, y) = map(int, input().split())
	i = (x ^ lastans) % N
	if op == 1:
		seqs[i].append(y)
	else:
		val = seqs[i][y % len(seqs[i])]
		print(val)
		lastans = val


(n, q) = [int(i) for i in input().strip().split(' ')]
a = []
for i in range(0, q):
	a.append([int(i) for i in input().strip().split(' ')])
seq = []
for i in range(0, n):
	seq.append([])
lastans = 0
for q in a:
	(t, x, y) = q
	snum = (x ^ lastans) % n
	if t == 1:
		seq[snum].append(y)
	elif t == 2:
		size = len(seq[snum])
		enum = y % size
		lastans = seq[snum][enum]
		print(lastans)


a = input().split(' ')
n = int(a[0])
q = int(a[1])
seq = [[] for i in range(n)]
lastans = 0

def xorlastans(x, y, last, n):
	return (x ^ last) % n
i = 0
for i in range(q):
	inp = input().split(' ')
	if inp[0] == '1':
		z = xorlastans(int(inp[1]), int(inp[2]), lastans, n)
		seq[z].append(inp[2])
	else:
		z = xorlastans(int(inp[1]), int(inp[2]), lastans, n)
		size = len(seq[z])
		no = int(seq[z][int(inp[2]) % size])
		print(no)
		lastans = no


n = input().split()
N = int(n[0])
Q = int(n[1])
lastans = 0
seq = []
for i in range(N):
	seq.append([])
for i in range(Q):
	q = [int(j) for j in input().split()]
	if q[0] == 1:
		x = (q[1] ^ lastans) % N
		seq[x].append(q[2])
	else:
		x = (q[1] ^ lastans) % N
		l = q[2] % len(seq[x])
		print(seq[x][l])
		lastans = seq[x][l]


import sys

def dynamicArray():
	n = sys.stdin.readline()
	space = n.find(' ')
	N = int(n[:space])
	count = int(n[space + 1:])
	lastans = 0
	arr = []
	for i in range(N):
		arr.append([])
	while count > 0:
		count -= 1
		n = sys.stdin.readline()
		op = int(n[0])
		n = n[2:]
		space = n.find(' ')
		first = int(n[:space])
		second = int(n[space + 1:])
		if op == 1:
			index = (first ^ lastans) % N
			arr[index].append(second)
		elif op == 2:
			index = (first ^ lastans) % N
			valIndex = second % len(arr[index])
			val = arr[index][valIndex]
			lastans = val
			print(val)
dynamicArray()


(N, Q) = [int(x) for x in input().split()]
seqs = [[] for _ in range(N)]
lastans = 0
for q in range(Q):
	(k, x, y) = [int(x) for x in input().split()]
	x_ = (x ^ lastans) % N
	if k == 1:
		seqs[x_].append(y)
	else:
		seq = seqs[x_]
		lastans = seq[y % len(seq)]
		print(lastans)


(n, q) = input().strip().split(' ')
(n, q) = (int(n), int(q))
strings = [[] for i in range(int(n))]
lastans = 0
for i in range(int(q)):
	(a, x, y) = input().strip().split(' ')
	(a, x, y) = (int(a), int(x), int(y))
	if a == 1:
		strings[(x ^ lastans) % n].append(y)
	elif a == 2:
		string = strings[(x ^ lastans) % n]
		print(string[y % len(string)])
		lastans = int(string[y % len(string)])


(n, q) = map(int, input().split())
seq = []
for i in range(n):
	seq += [[]]
la = 0
for i in range(q):
	(a, b, c) = map(int, input().split())
	if a == 1:
		seq[(b ^ la) % n].append(c)
	elif a == 2:
		print(seq[(b ^ la) % n][c % len(seq[(b ^ la) % n])])
		la = seq[(b ^ la) % n][c % len(seq[(b ^ la) % n])]


bigarr = []
metaData = [int(arr_temp) for arr_temp in input().strip().split(' ')]
(arraySize, queries) = (metaData[0], metaData[1])
finalArray = [[] for i in range(0, arraySize)]
for i in range(0, queries):
	bigarr.append([int(arr_temp) for arr_temp in input().strip().split(' ')])
lastans = 0
for i in bigarr:
	(command, no1, no2) = i
	shift = (lastans ^ no1) % arraySize
	if command == 1:
		finalArray[shift].append(no2)
	elif command == 2:
		sAS = len(finalArray[shift])
		lastans = finalArray[shift][no2 % sAS]
		print(lastans)


lastans = 0
(N, Q) = (int(x) for x in input().split(' '))
sequences = [[] for i in range(N)]
for i in range(Q):
	(command, x, y) = (int(x) for x in input().split(' '))
	index = (x ^ lastans) % N
	if command == 1:
		sequences[index].append(y)
	elif command == 2:
		size = len(sequences[index])
		lastans = sequences[index][y % size]
		print(lastans)


(N, Q) = [int(val) for val in input().strip().split()]
sequences = []
for _ in range(N):
	sequences.append([])
lastans = 0
for _ in range(Q):
	query = [int(val) for val in input().strip().split()]
	if query[0] == 1:
		sequences[(query[1] ^ lastans) % N].append(query[2])
	else:
		lastans = sequences[(query[1] ^ lastans) % N][query[2] % len(sequences[(query[1] ^ lastans) % N])]
		print(lastans)


last = 0
(n, q) = input().split()
(n, q) = (int(n), int(q))
a = [[] for _ in range(n)]
for _ in range(q):
	query = input().split()
	(x, y) = (int(query[1]), int(query[2]))
	if query[0] == '1':
		a[(x ^ last) % n].append(y)
	else:
		seq = a[(x ^ last) % n]
		last = seq[y % len(seq)]
		print(last)


text = input().strip().split(' ')
n = int(text[0])
q = int(text[1])
results = []
for i in range(n):
	results.append([])
lastans = 0
for i in range(q):
	text = input().strip().split(' ')
	n1 = int(text[0])
	n2 = int(text[1])
	n3 = int(text[2])
	if n1 == 1:
		results[(n2 ^ lastans) % n].append(n3)
	else:
		target = results[(n2 ^ lastans) % n]
		result = target[n3 % len(target)]
		print(target[n3 % len(target)])
		lastans = result


first_line = input().split(' ')
N = int(first_line[0])
Q = int(first_line[1])
lastans = 0
seqs = []
for i in range(N):
	seqs.append([])
for i in range(Q):
	line = input().split(' ')
	x = int(line[1])
	y = int(line[2])
	if line[0] == '1':
		seqs[(x ^ lastans) % N].append(y)
	else:
		seq = seqs[(x ^ lastans) % N]
		lastans = seq[y % len(seq)]
		print(lastans)


(N, Q) = map(int, input().split(' '))
sequences = []
lastans = 0
for i in range(N):
	sequences.append([])
for i in range(Q):
	(t, x, y) = map(int, input().split(' '))
	index = (x ^ lastans) % N
	curr_seq = sequences[index]
	if t == 1:
		curr_seq.append(y)
	elif t == 2:
		val = curr_seq[y % len(curr_seq)]
		print(val)
		lastans = val


(N, Q) = input().strip().split(' ')
(N, Q) = (int(N), int(Q))
seq = [[] for i in range(N)]
lastans = 0
for q in range(Q):
	(t, x, y) = input().strip().split(' ')
	(t, x, y) = (int(t), int(x), int(y))
	x = (x ^ lastans) % N
	if t == 1:
		seq[x].append(y)
	else:
		y = y % len(seq[x])
		print(seq[x][y])
		lastans = seq[x][y]


def dynamic_array():
	(N_str, Q_str) = input().strip().split()
	(N, Q) = (int(N_str), int(Q_str))
	sequences = []
	for i in range(N):
		sequences.append([])
	lastans = 0
	for i in range(Q):
		line_values = input().strip().split()
		(query_type, x, y) = (int(line_values[0]), int(line_values[1]), int(line_values[2]))
		if query_type == 1:
			sequences[(x ^ lastans) % N].append(y)
		else:
			s = sequences[(x ^ lastans) % N]
			lastans = s[y % len(s)]
			print(lastans)
dynamic_array()


(n, q) = [int(x) for x in input().strip().split(' ')]
arrs = [[int(x) for x in input().strip().split(' ')] for x in range(q)]
lastans = 0
seqs = [[] for x in range(n)]
for query in arrs:
	seq = seqs[(query[1] ^ lastans) % n]
	if query[0] == 1:
		seq.append(query[2])
	else:
		ret = seq[query[2] % len(seq)]
		print(ret)
		lastans = ret


temp = list(map(int, input().split(' ')))
n = temp[0]
q = temp[1]
seq = [[] for i in range(n)]
lastans = 0
for i in range(q):
	query = list(map(int, input().split(' ')))
	index = (query[1] ^ lastans) % n
	if query[0] == 1:
		seq[index].append(query[2])
	else:
		elementIndex = query[2] % len(seq[index])
		lastans = seq[index][elementIndex]
		print(lastans)


(n, q) = [int(x) for x in input().split(' ')]
arr = [[] for _ in range(n)]
lastans = 0
for _ in range(q):
	(cmd, x, y) = [int(x) for x in input().split(' ')]
	if cmd == 1:
		arr[(x ^ lastans) % n] += [y]
	elif cmd == 2:
		a = arr[(x ^ lastans) % n]
		v = a[y % len(a)]
		print(v)
		lastans = v


a = input().split()
n = int(a[0])
Q = int(a[1])
lastans = 0
seqs = []
for i in range(n):
	seqs.append([])
for q in range(Q):
	query = input().split()
	if int(query[0]) == 1:
		seqs[(lastans ^ int(query[1])) % n].append(int(query[2]))
	if int(query[0]) == 2:
		print(seqs[(lastans ^ int(query[1])) % n][int(query[2]) % len(seqs[(lastans ^ int(query[1])) % n])])
		lastans = seqs[(lastans ^ int(query[1])) % n][int(query[2]) % len(seqs[(lastans ^ int(query[1])) % n])]


inputTokens = input().split()
n = int(inputTokens[0])
q = int(inputTokens[1])
lastans = 0
seq = []
for i in range(n):
	seq.append([])
for i in range(q):
	inputTokens = input().split()
	operation = int(inputTokens[0])
	seqIndex = (int(inputTokens[1]) ^ lastans) % n
	val = int(inputTokens[2])
	if operation == 1:
		seq[seqIndex].append(val)
	else:
		lastans = seq[seqIndex][val % len(seq[seqIndex])]
		print(lastans)


lastans = 0
array = list(map(lambda x: int(x), input().split(' ')))
N = array[0]
sequences = [[] for x in range(N)]
for i in range(array[1]):
	qarray = list(map(lambda x: int(x), input().split(' ')))
	if qarray[0] == 1:
		sequences[(qarray[1] ^ lastans) % N].append(qarray[2])
	else:
		lastans = sequences[(qarray[1] ^ lastans) % N][qarray[2] % len(sequences[(qarray[1] ^ lastans) % N])]
		print(lastans)


(n, q) = map(int, input().split())
ans = 0
a = [[] for i in range(n)]
for i in range(q):
	(op, x, y) = map(int, input().split())
	if op == 1:
		a[(ans ^ x) % n].append(y)
	else:
		b = a[(ans ^ x) % n]
		ans = b[y % len(b)]
		print(ans)


def query_one(sequence, y):
	sequence.append(y)

def query_two(sequence, y):
	value = sequence[y % len(sequence)]
	print(value)
	return value
(N, Q) = (int(val) for val in input().split())
sequences = [[] for _ in range(N)]
lastans = 0
for _ in range(Q):
	(switch, x, y) = (int(val) for val in input().split())
	sequence = sequences[(x ^ lastans) % N]
	if switch is 1:
		query_one(sequence, y)
	else:
		lastans = query_two(sequence, y)


(N, Q) = map(int, input().split())
arr = [[] for _ in range(N)]
last = 0
for _ in range(Q):
	(t, x, y) = map(int, input().split())
	if t == 1:
		arr[(x ^ last) % N].append(y)
	if t == 2:
		a = arr[(x ^ last) % N]
		num = a[y % len(a)]
		last = num
		print(num)


(n, q) = map(int, input().split())
lastans = 0
ar = [[] for i in range(n + 1)]
sizes = [0] * (n + 1)
for i in range(q):
	(op, x, y) = map(int, input().split())
	if op == 1:
		target = (x ^ lastans) % n
		ar[target].append(y)
		sizes[target] += 1
	else:
		target = (x ^ lastans) % n
		lastans = ar[target][y % sizes[target]]
		print(lastans)


from collections import defaultdict
(n, q) = list(map(int, input().strip().split(' ')))
lastans = 0
master = defaultdict(list)
for i in range(q):
	(typ, x, y) = list(map(int, input().strip().split(' ')))
	key = (x ^ lastans) % n
	if typ == 1:
		master[key].append(y)
	elif typ == 2:
		size = len(master[key])
		lastans = master[key][y % size]
		print(lastans)
	else:
		print('invalid query type')


l = []
lastans = 0
NQ = input().split()
N = int(NQ[0])
Q = int(NQ[1])
for i in range(N):
	l.append([])
for i in range(Q):
	query = input().split()
	if query[0] == '1':
		x = int(query[1])
		y = int(query[2])
		ind = (x ^ lastans) % N
		l[ind].append(y)
	elif query[0] == '2':
		x = int(query[1])
		y = int(query[2])
		ind = (x ^ lastans) % N
		print(l[ind][y % len(l[ind])])
		lastans = l[ind][y % len(l[ind])]


(N, Q) = map(int, input().split())
arr = [[] for _ in range(N)]
last = 0
for _ in range(Q):
	(t, x, y) = map(int, input().split())
	if t == 1:
		arr[(x ^ last) % N].append(y)
	if t == 2:
		a = arr[(x ^ last) % N]
		num = a[y % len(a)]
		last = num
		print(num)


(N, Q) = input().split()
N = int(N)
Q = int(Q)
SEQUENCES = [[] for i in range(N)]
lastanswer = 0

def get_queries():
	for _ in range(Q):
		yield [int(value) for value in input().strip().split()]
for (op, x, y) in get_queries():
	index = (x ^ lastanswer) % N
	sequence = SEQUENCES[index]
	if op == 1:
		sequence.append(y)
		continue
	subindex = y % len(sequence)
	lastanswer = sequence[subindex]
	print(lastanswer)


(N, Q) = map(int, input().split())
lastans = 0
sequences = [[] for _ in range(N)]
for _ in range(Q):
	(operation, x, y) = map(int, input().split())
	if operation == 1:
		sequences[(x ^ lastans) % N].append(y)
	elif operation == 2:
		sequence = sequences[(x ^ lastans) % N]
		lastans = sequence[y % len(sequence)]
		print(lastans)


(N, Q) = map(int, input().split())
arr = [[] for _ in range(N)]
last = 0
for _ in range(Q):
	(t, x, y) = map(int, input().split())
	if t == 1:
		arr[(x ^ last) % N].append(y)
	if t == 2:
		a = arr[(x ^ last) % N]
		num = a[y % len(a)]
		last = num
		print(num)


class DynamicArray:

	def __init__(self, n):
		self.arrays = [[] for i in range(n)]
		self.N = n
		self.lastans = 0

	def query(self, input_string):
		d = [int(i) for i in input_string.split(' ')]
		if d[0] == 1:
			self.ins(d[1], d[2])
		elif d[0] == 2:
			self.pr(d[1], d[2])

	def ins(self, x, y):
		seq = (x ^ self.lastans) % self.N
		self.arrays[seq].append(y)

	def pr(self, x, y):
		seq = (x ^ self.lastans) % self.N
		size = len(self.arrays[seq])
		el = y % size
		int_to_print = self.arrays[seq][el]
		print(int_to_print)
		self.lastans = int_to_print
fl = input().strip().split(' ')
d = DynamicArray(int(fl[0]))
for i in range(int(fl[1])):
	d.query(input().strip())


(n, q) = tuple([int(s) for s in input().split()])
seqs = []
for i in range(n):
	seqs.append([])
lastans = 0
for _ in range(q):
	(op, x, y) = tuple([int(s) for s in input().split()])
	seq_id = (x ^ lastans) % n
	if op == 1:
		seqs[seq_id].append(y)
	elif op == 2:
		el_id = y % len(seqs[seq_id])
		print(seqs[seq_id][el_id])
		lastans = seqs[seq_id][el_id]


[N, Q] = [int(x) for x in input().strip().split()]
allstr = [[] for _ in range(N)]
lastans = 0
for i in range(Q):
	[t, p, ins] = [int(x) for x in input().strip().split()]
	position = (p ^ lastans) % N
	if t == 1:
		allstr[position].append(ins)
	else:
		size = len(allstr[position])
		value = allstr[position][ins % size]
		print(value)
		lastans = value


line1 = input().split()
N = int(line1[0])
Q = int(line1[1])
lastans = 0
sequences = []
for _ in range(N):
	sequences.append([])
for _ in range(Q):
	query = [int(string) for string in input().split()]
	_type = query[0]
	x = query[1]
	y = query[2]
	if _type == 1:
		sequence_index = (x ^ lastans) % N
		sequences[sequence_index].append(y)
	elif _type == 2:
		sequence_index = (x ^ lastans) % N
		element_index = y % len(sequences[sequence_index])
		lastans = sequences[sequence_index][element_index]
		print(lastans)