Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.

Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$.

Currently, Chef is busy in the kitchen making this tasty matrix. Help him find the bitwise XOR of all elements of this matrix.

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains three space-separated integers $N$, $M$ and $K$.

------  Output ------
For each test case, print a single line containing one integer ― the bitwise XOR of all elements of the tasty matrix with the given dimensions made with the given special ingredient. 

------  Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N, M ≤ 2 \cdot 10^{6}$
$1 ≤ K ≤ 10^{9}$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{6}$
the sum of $M$ over all test cases does not exceed $2 \cdot 10^{6}$

----- Sample Input 1 ------ 
2

2 2 5

2 3 7
----- Sample Output 1 ------ 
14

5
----- explanation 1 ------ 
Example case 1: The matrix is
$$A = \begin{pmatrix}
5 + 1 + 1 & 5 + 1 + 2\\
5 + 2 + 1 & 5 + 2 + 2\end{pmatrix}
= \begin{pmatrix}
7 & 8 \\
8 & 9 
\end{pmatrix} \,.$$

The XOR of all its elements is $7 \oplus 8 \oplus 8 \oplus 9 = 14$.

Example case 2: The matrix is
$$A = \begin{pmatrix}
7 + 1 + 1 & 7 + 1 + 2 & 7 + 1 + 3\\
7 + 2 + 1 & 7 + 2 + 2 & 7 + 2 + 3
\end{pmatrix}
= \begin{pmatrix}
9 & 10 & 11\\
10 & 11 & 12
\end{pmatrix} \,.$$

The XOR of all its elements is $9 \oplus 10 \oplus 11 \oplus 10 \oplus 11 \oplus 12 = 5$.

Source: codechef | Difficulty: MEDIUM_HARD
Tags: Bit manipulation

Constructive algorithms

Mathematics

Ad-hoc


Solutions:
T = int(input())
for _ in range(T):
	(N, M, K) = map(int, input().split())
	res = 0
	for j in range(1, M + 1):
		if j <= N and j % 2 == 1:
			res = res ^ K + j + 1
		elif j > N and N % 2 == 1:
			res = res ^ K + j + 1
	for j in range(M + 1, N + M):
		if j > N and (N + M - j) % 2 == 1:
			res = res ^ K + j + 1
		elif j <= N and M % 2 == 1:
			res = res ^ K + j + 1
	print(res)


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	e = 0
	for i in range(2, a + 2):
		d = min(i - 1, b)
		if d % 2 == 0:
			pass
		else:
			e ^= i + c
	for i in range(a + 2, a + b + 1):
		f = min(a, b - (i - a) + 1)
		if f % 2 == 0:
			pass
		else:
			e ^= i + c
	print(e)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	ans = 0
	for i in range(1, n + 1 - n % 2):
		if i & 1:
			ans ^= k + i + 1
		else:
			ans ^= k + i + m
	if n & 1:
		for i in range(1, m + 1):
			ans ^= k + n + i
	print(ans)


T = int(input())

def solve(N, M, K):
	if N > M:
		(N, M) = (M, N)
	ans = 0
	for k1 in range(2, N + M + 1):
		if (min(k1 - 1, N) - max(1, k1 - M) + 1) % 2:
			ans = ans ^ k1 + K
	return ans
for _ in range(T):
	(N, M, K) = [int(s) for s in input().split()]
	print(solve(N, M, K))


n = int(input())
for i in range(n):
	(r, c, k) = list(map(int, input().split(' ')))
	res = 0
	for i in range(1, r + 1):
		if min(i, c) % 2 != 0:
			res = res ^ k + i + 1
	for j in range(2, c + 1):
		if min(r, c - j + 1) % 2 != 0:
			res = res ^ k + r + j
	print(res)


t = int(input())
for i in range(t):
	(n, m, k) = list(map(int, input().split()))
	ans = 0
	for i in range(1, n + 1):
		if min(i, m) % 2 != 0:
			ans ^= k + i + 1
	for j in range(2, m + 1):
		if min(n, m - j + 1) % 2 != 0:
			ans ^= k + n + j
	print(ans)


for i in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	x = 0
	r = 0
	if n % 2 == 0:
		r = n
	else:
		r = n - 1
		for i in range(1, m + 1):
			x ^= k + n + i
	for i in range(1, r + 1):
		if i % 2 == 1:
			x ^= k + i + 1
		else:
			x ^= k + i + m
	print(x)


from math import *
import sys

def input():
	return sys.stdin.readline().replace('\n', '').strip()
sys.setrecursionlimit(10 ** 9)
for _ in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	l = [i for i in range(2 + k, k + m + n + 1)]
	l2 = [-1 for i in range(2 + k, k + m + n + 1)]
	ans = 0
	m = min(m, n)
	for i in range(1, m + 1):
		l2[i - 1] = i
	for i in range(-1, -m - 1, -1):
		l2[i] = -i
	for i in range(len(l2)):
		if l2[i] == -1:
			l2[i] = m
	for i in range(len(l2)):
		if l2[i] % 2 == 1:
			ans ^= l[i]
	print(ans)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	ans = 0
	if n == 1 or m == 1:
		for i in range(max(n, m)):
			ans ^= k + 2 + i
	else:
		for i in range((n + m) // 2):
			if i < min(n, m):
				if i % 2 == 0:
					ans ^= k + i + 2
					ans ^= k + n + m - i
			elif min(n, m) % 2 == 1:
				ans ^= k + i + 2
				ans ^= k + n + m - i
		if (n + m) % 2 == 0 and max(n, m) % 2 == 1:
			ans ^= k + (n + m) // 2 + 1
	print(ans)


from operator import ixor
T = int(input())
for i in range(T):
	(N, M, K) = map(int, input().split(' '))
	sum1 = 0
	for j in range(1, N + 1):
		if min(j, M) % 2 != 0:
			sum1 = sum1 ^ K + j + 1
	for j in range(2, M + 1):
		if min(M - j + 1, N) % 2 != 0:
			sum1 = sum1 ^ K + N + j
	print(sum1)


import math
import random as rd
import bisect
import collections

def combination(n, r):
	return math.comb(n, r)

def listing():
	return list(map(int, input().split()))

def intp():
	return int(input())

def inp():
	return input()

def inpspl():
	return input().split()

def mapping():
	return map(int, input().split(' '))

def sqrt(n):
	return math.sqrt(n)

def gcd(a, b):
	return math.gcd(a, b)

def lcm(a, b):
	return a * b // gcd(a, b)

def p(s):
	print(f'{s}')

def lsetl(lst):
	return list(set(lst))

def nCr(n, r):
	f = math.factorial
	return f(n) // f(r) // f(abs(n - r))

def frequencyofall(lst):
	return dict(collections.Counter(lst))

def ispowerof2(n):
	return n & n - 1 == 0

def ispowerof3(n):
	return math.log10(n) / math.log10(3) % 1 == 0

def dictionarysort(d):
	return collections.OrderedDict(sorted(d.items()))

def bintoint(s):
	return int(s, 2)

def solve():
	for _ in range(int(input())):
		(n, m, k) = map(int, input().split())
		ans = 0
		for i in range(1, n + 1):
			if min(i, m) % 2 == 1:
				ans ^= k + i + 1
		for i in range(2, m + 1):
			if min(n, m - i + 1) % 2 == 1:
				ans ^= k + n + i
		print(ans)
solve()


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	ans = 0
	while m or n:
		for i in range(1, min(n, m) + 1):
			ans = ans ^ k + i + i
		if n < m:
			m = m - n
			k += n
		elif n > m:
			n = n - m
			k += m
		else:
			break
	print(ans)


import os.path
from math import gcd, floor, ceil
from collections import *
import sys
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

def li():
	return list(map(int, sys.stdin.readline().split()))

def mp():
	return map(int, sys.stdin.readline().split())

def inp():
	return int(sys.stdin.readline())

def pr(n):
	return sys.stdout.write(str(n) + '\n')

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():

	def FIND(start, end):
		if start == end and start % 2 == 0:
			return start
		xor_r = 2 * XOR(end // 2)
		xor_l = 2 * XOR((start - 1) // 2)
		return xor_l ^ xor_r

	def XOR(n):
		c = n
		n %= 4
		if n == 0:
			return c
		if n == 1:
			return 1
		if n == 2:
			return c + 1
		if n == 3:
			return 0
	(n, m, k) = mp()
	if n == 1:
		pr(XOR(m) ^ 1)
		return
	if m == 1:
		pr(XOR(n) ^ 1)
		return
	ans = 0
	if n % 2:
		ans = XOR(k + n + m) ^ XOR(k + n)
	start = k + 2
	end = k + n // 2 * 2
	if start % 2:
		ans ^= XOR(end) ^ FIND(start, end) ^ XOR(start - 1)
	else:
		ans ^= FIND(start, end)
	start = k + m + 2
	end = k + m + 2 + (n - 2) // 2 * 2
	if start % 2:
		ans ^= XOR(end) ^ FIND(start, end) ^ XOR(start - 1)
	else:
		ans ^= FIND(start, end)
	print(ans)
for _ in range(inp()):
	solve()


t = int(input())
for _ in range(t):
	(n, m, k) = list(map(int, input().split()))
	if n > m:
		(m, n) = (n, m)
	res = 0
	for i in range(n):
		if i % 2 == 0:
			res ^= i + k + 2
			if i != m - 1:
				res ^= n + m - i + k
	if n % 2 == 1:
		for j in range(1, m - n):
			res ^= n + j + k + 1
	print(res)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	ans = 0
	if min(m, n) == 1:
		for i in range(1, max(m, n)):
			ans ^= k + i + 1
	else:
		ans = 0
		x = min(m, n)
		y = max(m, n)
		for i in range(1, x, 2):
			ans ^= k + i + 1
		if x & 1:
			for i in range(x, y + 1):
				ans ^= k + i + 1
		for i in range(x + y - 1, y, -2):
			ans ^= k + i + 1
	print(ans)


for _ in range(int(input())):
	(N, M, K) = map(int, input().strip().split())
	last = 0
	for i in range(1, N // 2 + 1):
		last ^= K + i * 2
		last ^= K + M + i * 2
	if N % 2 != 0:
		for i in range(K + N + 1, K + N + M + 1):
			last ^= i
	print(last)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	o = 0
	for i in range(1, m + 1):
		j = min(i, n)
		if j % 2 == 1:
			o ^= k + i + 1
	for i in range(2, n + 1):
		j = min(n - i + 1, m)
		if j % 2 == 1:
			o ^= k + m + i
	print(o)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	a = 0
	for i in range(2, m + n + 1):
		l = max(1, i - m)
		r = min(n, i - 1)
		if r >= l and (r - l + 1) % 2 == 1:
			a ^= k + i
	print(a)


def findxor(s):
	if s % 4 == 0:
		return s
	elif s % 4 == 1:
		return 1
	elif s % 4 == 2:
		return s + 1
	elif s % 4 == 3:
		return 0
for t in range(int(input())):
	(n, m, k) = map(int, input().split())
	ans = findxor(k + 1) ^ findxor(k + m + 1)
	for i in range(2, n + 1):
		ans = ans ^ (findxor(k + i) ^ findxor(k + m + i))
	print(ans)


t = int(input())
for _ in range(t):
	(x, y, k) = map(int, input().split())
	if x > y:
		(x, y) = (y, x)
	ans = 0
	for m in range(1, y + 1):
		c = min(x, m)
		if c & 1 == 1:
			ans = ans ^ k + 1 + m
	for n in range(2, x + 1):
		c = x - n + 1
		if c & 1 == 1:
			ans = ans ^ k + n + m
	print(ans)


T = int(input())

def xor(T):
	mod = T % 4
	if mod == 0:
		return T
	if mod == 1:
		return 1
	if mod == 2:
		return T + 1
	if mod == 3:
		return 0
for _ in range(T):
	(N, M, K) = map(int, input().split())
	s = xor(1 + K) ^ xor(1 + K + M)
	for i in range(2, N + 1):
		s = s ^ xor(i + K) ^ xor(i + M + K)
	print(s)


t = int(input())
while t > 0:
	(N, M, K) = [int(i) for i in input().split()]
	ans = 0
	for i in range(1, N + 1):
		if min(i, M) % 2 == 1:
			ans ^= K + i + 1
	for j in range(2, M + 1):
		if min(N, M - j + 1) % 2 == 1:
			ans ^= K + N + j
	print(ans)
	t -= 1


T = int(input())
for i in range(T):
	(n, m, k) = tuple(map(int, input().split()))
	res = 0
	n_v = 0
	if n % 2 == 0:
		n_v = n
	else:
		n_v = n - 1
		for i in range(1, m + 1):
			res ^= k + n + i
	for i in range(1, n_v + 1):
		if i % 2 == 1:
			res ^= k + i + 1
		else:
			res ^= k + i + m
	print(res)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	c = 0
	x = 0
	if n % 2 == 0:
		x = n
	else:
		x = n - 1
	for i in range(1, x + 1):
		if i % 2 == 1:
			c ^= k + i + 1
		else:
			c ^= k + m + i
	if n % 2 == 1:
		for j in range(1, m + 1):
			c ^= n + j + k
	print(c)


def solve(n, m, k):
	res = 0
	for i in range(1, n):
		if i % 2 == 0:
			res ^= k + i + m
		else:
			res ^= k + i + 1
	if n % 2 == 0:
		res ^= k + n + m
	else:
		for j in range(1, m + 1):
			res ^= k + j + n
	return res

def main():
	for _ in range(int(input())):
		(n, m, k) = map(int, input().split())
		ans = solve(n, m, k)
		print(ans)
main()


t = int(input())
while t:
	(n, m, k) = map(int, input().split())
	v = k + 1 + 1
	v = v ^ k + m + n
	c = 2
	for i in range(k + 3, k + n + 2):
		y = min(c, m)
		if y % 2 != 0:
			v = v ^ i
		c += 1
	c = 2
	for i in range(k + n + 2, k + n + m):
		y = min(n, m - c + 1)
		if y % 2 != 0:
			v = v ^ i
		c += 1
	print(v)
	t -= 1


def xor(number):
	if number % 4 == 0:
		return number
	elif number % 4 == 1:
		return 1
	elif number % 4 == 2:
		return number + 1
	else:
		return 0
T = int(input())
for _ in range(T):
	(N, M, K) = map(int, input().split())
	lst = [xor(K + i) ^ xor(K + i + M) for i in range(1, N + 1)]
	res = 0
	for e in lst:
		res ^= e
	print(res)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	sum = 0
	for i in range(1, n):
		count = min(m, i)
		if count % 2 == 0:
			pass
		else:
			sum = sum ^ i + 1 + k
	for j in range(1, m + 1):
		count1 = min(n, m - j + 1)
		if count1 % 2 == 0:
			pass
		else:
			sum = sum ^ j + n + k
	print(sum)


def solve():
	(n, m, k) = inl()
	ans = 0
	for i in range(1, n + 1):
		if min(i, m) % 2 != 0:
			ans ^= k + i + 1
	for j in range(2, m + 1):
		if min(n, m - j + 1) % 2 != 0:
			ans ^= k + n + j
	print(ans)

def inl():
	return [int(i) for i in input().split()]

def inp():
	return int(input())
t = 1
t = inp()
while t:
	solve()
	t -= 1


for t in range(int(input())):
	(n, m, k) = map(int, input().split())
	c = 0
	for i in range(1, n + 1):
		x = min(i, m)
		if x % 2 != 0:
			c ^= i + k + 1
	for j in range(2, m + 1):
		x = min(n, m - j + 1)
		if x % 2 != 0:
			c ^= n + k + j
	print(c)


def prog_name():
	(n, m, k) = map(int, input().split())
	x = 0
	c = 0
	if n % 2 == 0:
		x = n
	else:
		x = n - 1
	for x in range(1, x + 1):
		if x % 2 == 1:
			c ^= k + x + 1
		else:
			c ^= k + m + x
	if n % 2 == 1:
		for y in range(1, m + 1):
			c ^= k + y + n
	print(c)
t = int(input())
for unique in range(t):
	prog_name()


test_case = int(input())
for n1 in range(test_case):
	(n, m, k) = [int(i) for i in input().split(' ')]
	l = list(range(1, min(n, m))) + [min(n, m)] * (abs(m - n) + 1) + list(range(1, min(n, m)))[::-1]
	a = 0
	for i in range(len(l)):
		a ^= (k + 2 + i) * (l[i] % 2)
	print(a)


try:
	t = int(input())
	input_str = []
	for i in range(t):
		input_str.append(input())
	for inputt in input_str:
		(rows, cols, k) = [int(ele) for ele in inputt.split()]
		res = 0
		for i in range(1, rows + 1):
			if min(i, cols) % 2 == 1:
				res ^= k + i + 1
		for j in range(2, cols + 1):
			if min(rows, cols - j + 1) % 2 == 1:
				res ^= k + rows + j
		print(res)
except:
	pass


for t in range(int(input())):
	l = list(map(int, input().split()))
	n = l[0]
	m = l[1]
	k = l[2]
	r = []
	for i in range(1, n + 1):
		r.append((1 + i, i, 1))
	for j in range(2, m + 1):
		r.append((n + j, n, j))
	ans = 0
	for i in range(len(r)):
		v = r[i]
		if i < n:
			if min(v[1], m) % 2 == 1:
				ans = ans ^ k + v[0]
		elif min(m - v[2] + 1, n) % 2 == 1:
			ans = ans ^ k + v[0]
	print(ans)


try:
	t = int(input())
	for _ in range(t):
		(n, m, k) = map(int, input().split())
		res = 0
		for i in range(1, n + 1):
			if min(i, m) % 2 != 0:
				res ^= k + 1 + i
		for j in range(2, m + 1):
			if min(n, m - j + 1) % 2 != 0:
				res ^= k + n + j
		print(res)
except:
	pass


for _ in range(int(input())):
	(r, c, k) = map(int, input().split())
	ans = 0
	for j in range(1, c + 1):
		p = min(r - 1, j - 1) + 1
		if p % 2:
			ans ^= 1 + j + k
	for i in range(2, r + 1):
		p = min(c - 1, r - i) + 1
		if p % 2:
			ans ^= i + c + k
	print(ans)


import sys
intinp = lambda : int(input())

def listinp(func=int):
	return list(map(func, input().split()))

def nsepline(n, func=str):
	return [func(input()) for _ in range(n)]

def printlist(li, glue=' '):
	return glue.join(list(map(str, li)))

def fop(s, end='\n'):
	sys.stdout.write(str(s) + end)

def fip():
	return sys.stdin.readline().strip()
fintinp = lambda : int(fip())

def flistinp(func=int):
	return list(map(func, fip().split()))

def fnsepline(n, func=str):
	return [func(fip()) for _ in range(n)]

def inDifAr(a):
	d = a[0:1] + [0] * len(a)
	for i in range(1, len(a)):
		d[i] = a[i] - a[i - 1]
	return d

def update(l, r, x, d):
	d[l] += x
	d[r + 1] -= x

def updatedArr(a, d):
	a[0] = d[0]
	for i in range(1, len(a)):
		a[i] = d[i] + a[i - 1]
test_cases = fintinp()
for _ in range(test_cases):
	(n, m, k) = flistinp()
	l = [0] * (n + m + 5)
	D = inDifAr(l)
	for i in range(n):
		update(2 + i, 1 + i + m, 1, D)
	updatedArr(l, D)
	ans = 0
	for i in range(2, n + m + 1):
		if l[i] % 2 == 1:
			ans ^= i + k
	print(ans)


T = int(input())
ans = []
for _ in range(T):
	(N, M, K) = [int(i) for i in input().split()]
	l = 1
	a = None
	X = min(N, M)
	for i in range(K + 2, K + M + 1 + 1):
		if a == None:
			a = K + 2
		elif l % 2 != 0:
			a ^= i
		l = min(l + 1, X)
	l = 1
	for i in range(K + N + M, K + M + 1, -1):
		if l % 2 != 0:
			a ^= i
		l = min(l + 1, X)
	ans.append(a)
for i in ans:
	print(i)


from collections import defaultdict
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if n == m:
		ans = k + 2
		for i in range(2, n + 1):
			ans ^= k + i + i
		print(ans)
		continue
	ans = 0
	for i in range(1, n + 1):
		if min(i, m) % 2 == 1:
			ans = ans ^ i + 1 + k
	for i in range(2, m + 1):
		if min(n, m - i + 1) % 2 == 1:
			ans = ans ^ i + n + k
	print(ans)


def solve(n, m, k):
	res = 0
	for i in range(1, n + 1):
		if min(i, m) % 2 == 1:
			res = res ^ i + 1 + k
	for i in range(2, m + 1):
		if min(n, m - i + 1) % 2 == 1:
			res = res ^ i + n + k
	return res
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	ans = solve(n, m, k)
	print(ans)


for t in range(int(input())):
	(nr, nc, K) = map(int, input().split())
	xor = 0
	min_rc = min(nr, nc)
	counts = [min_rc] * (nr + nc - 1)
	for i in range(min_rc):
		counts[i] = counts[-(i + 1)] = i + 1
	for (i_plus_j, count) in zip(range(2, nc + nr + 1), counts):
		if count % 2 != 0:
			xor ^= K + i_plus_j
	print(xor)


import sys
input = sys.stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())

def solve():
	(n, m, k) = R()
	if m > n:
		(n, m) = (m, n)
	ans = 0
	for i in range(1, n + 1):
		t = min(i, m)
		if t & 1:
			ans ^= i + k + 1
	for i in range(1, m):
		t = m - i
		if t & 1:
			ans ^= n + i + 1 + k
	print(ans)
for _ in range(I()):
	solve()


def xor_calculator(n, m, k):
	ans = 0
	for i in range(1, n + 1):
		if min(i, m) % 2 != 0:
			ans = ans ^ k + i + 1
	for j in range(2, m + 1):
		if min(n, m - j + 1) % 2 != 0:
			ans = ans ^ n + j + k
	return ans
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	print(xor_calculator(n, m, k))


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	count = 1
	ans = 0
	for j in range(k + 2, k + m + 1):
		if count >= n:
			if n % 2 == 0:
				break
			else:
				ans ^= j
		elif count % 2 != 0:
			ans ^= j
		count += 1
	count = 1
	for j in range(k + m + n, k + m, -1):
		if count >= m:
			if m % 2 == 0:
				break
			else:
				ans ^= j
		elif count % 2 != 0:
			ans ^= j
		count += 1
	print(ans)


for t in range(int(input())):
	(n, m, k) = map(int, input().split())
	dt = dict()
	tp = k + 2
	for i in range(1, n + 1):
		dt[tp] = min(i, m)
		tp += 1
	for j in range(2, m + 1):
		dt[tp] = min(n, m - j + 1)
		tp += 1
	ans = 0
	for (key, value) in dt.items():
		if value % 2:
			ans = ans ^ key
	print(ans)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	arr = [i for i in range(2, n + m + 1)]
	diffarray = [0] * (n + m + 1)
	for i in range(n):
		diffarray[i] += 1
		diffarray[i + m] -= 1
	count = 0
	ans = 0
	for i in range(len(diffarray)):
		count += diffarray[i]
		if i <= len(arr):
			if count % 2 != 0:
				ans = ans ^ arr[i] + k
	print(ans)


try:
	for i in range(int(input())):
		(n, m, k) = map(int, input().split())
		ans = 0
		for i in range(1, n + 1):
			if min(i, m) % 2 == 1:
				ans ^= k + i + 1
		for i in range(2, m + 1):
			if min(n, m - i + 1) % 2 == 1:
				ans ^= k + n + i
		print(ans)
except:
	pass


for _ in range(int(input())):
	import numpy as np
	(n, m, k) = map(int, input().split())
	res = 0
	for i in range(1, n + 1):
		if min(i, m) % 2 == 1:
			res ^= k + i + 1
	for j in range(2, m + 1):
		if min(n, m - j + 1) % 2 == 1:
			res ^= k + n + j
	print(res)


T = int(input())
for t in range(T):
	(N, M, K) = [int(i) for i in input().split()]
	ans = 0
	j = 1
	for i in range(K + 2, K + N + M + 1):
		if j % 2 != 0:
			ans = ans ^ i
		if i <= min(N, M) + K:
			j += 1
		elif i >= K + max(N, M) + 1:
			j -= 1
	print(ans)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	x = k + 2
	y = k + n + m
	sum1 = 0
	for i in range(1, n + 1):
		if min(i, m) % 2 != 0:
			sum1 ^= k + i + 1
	for i in range(2, m + 1):
		if min(n, m - i + 1) % 2 != 0:
			sum1 ^= k + n + i
	print(sum1)


t = int(input())
r = []
for i in range(t):
	(n, m, k) = map(int, input().split())
	rs = 0
	xmax = max(n, m)
	xmin = min(n, m)
	for x in range(1, xmin // 2 + 1):
		rs = rs ^ 2 * x + k
		rs = rs ^ n + m - 2 * x + 2 + k
	if xmin % 2 == 1:
		for y in range(xmin // 2 + 1, xmax - xmin // 2 + 1):
			rs = rs ^ xmin // 2 + 1 + y + k
	r.append(rs)
for j in r:
	print(j)


for _ in range(int(input())):
	x = 0
	y = 0
	(N, M, K) = map(int, input().split())
	for i in range(1, N + 1):
		if min(i, M) % 2 == 1:
			x = x ^ K + i + 1
	for j in range(2, M + 1):
		if min(M - j + 1, N) % 2 == 1:
			x = x ^ K + j + N
	print(x)


T = int(input())
for k in range(T):
	(N, M, K) = [int(i) for i in input().split()]
	an = 0
	a = 1
	for i in range(K + 2, K + N + M + 1):
		if a % 2 != 0:
			an = an ^ i
		if i - K <= min(N, M):
			a += 1
		elif i - K + 1 >= max(N, M) + 2:
			a -= 1
	print(an)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	(n, m) = (min(n, m), max(n, m))
	ans = 0
	j = 2
	for i in range(1, n):
		if i % 2:
			ans ^= j + k
		j += 1
	if n % 2:
		while 1:
			ans ^= j + k
			j += 1
			if j == m + n - n + 2:
				break
	j = m + n - n + 2
	for i in range(n - 1, 0, -1):
		if i % 2:
			ans ^= j + k
		j += 1
	print(ans)


T = int(input())
for _ in range(T):
	(N, M, K) = map(int, input().split())
	ans = 0
	for i in range(1, N + 1):
		if min(i, M) % 2 == 1:
			ans ^= K + i + 1
	for j in range(2, M + 1):
		if min(N, M - j + 1) % 2 == 1:
			ans ^= K + N + j
	print(ans)


t = int(input())
for x in range(t):
	[n, m, k] = [int(y) for y in input().split()]
	if m == n:
		ans = 0
		for i in range(1, m + 1):
			ans ^= int(k + 2 * i)
		print(ans)
	elif m > n and n != 1:
		ans = 0
		if n % 2 == 0:
			for i in range(1, int(n / 2) + 1):
				ans ^= int(k + 2 * i) ^ int(k + m + 1 - i + n + 1 - i)
		else:
			for i in range(1, int((n + 1) / 2)):
				ans ^= int(k + 2 * i) ^ int(k + m + 1 - i + n + 1 - i)
			for i in range(int((n + 1) / 2), m - int((n - 1) / 2) + 1):
				ans ^= int(k + (n + 1) / 2 + i)
		print(ans)
	elif n > m and m != 1:
		temp = m
		m = n
		n = temp
		ans = 0
		if n % 2 == 0:
			for i in range(1, int(n / 2) + 1):
				ans ^= int(k + 2 * i) ^ int(k + m + 1 - i + n + 1 - i)
		else:
			for i in range(1, int((n + 1) / 2)):
				ans ^= int(k + 2 * i) ^ int(k + m + 1 - i + n + 1 - i)
			for i in range(int((n + 1) / 2), m - int((n - 1) / 2) + 1):
				ans ^= int(k + (n + 1) / 2 + i)
		print(ans)
	elif m == 1:
		ans = 0
		for i in range(1, n + 1):
			ans ^= int(k + i + m)
		print(ans)
	else:
		ans = 0
		for i in range(1, m + 1):
			ans ^= int(k + n + i)
		print(ans)