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

You are given an array $A$ with $N$ integers. An array's score is defined as the bitwise AND of all its elements. You need to find the bitwise OR of the scores of all possible non-empty subarrays of $A$.

Furthermore, there are $Q$ queries. Each query consists of two integers $X$ and $V$. You need to change the value of the element at index $X$ to $V$. After each query, you again need to find the bitwise OR of the scores of all possible non-empty subarrays.

See the example for more clarification.

------ Input: ------
The first line of the input contains a single integer $T$ - the number of test cases. The description of $T$ test cases follows.

The first line of each test case contains two space-separated integers $N$ and $Q$ - the size of the array and the number of queries, respectively.

The second line contains $N$ space-separated integers $A_{1},\ldots,A_{N}$.

Each of the next $Q$ lines contains two space-separated integers $X$ and $V$ - the position and the new value of the query, respectively.

------ Output: ------
For each test case print $Q+1$ lines. In the first line print the answer for the original array and in the next $Q$ lines print the answer after every query.

------ Constraints  ------
$1 ≤ T ≤ 100$

$1 ≤ N, Q ≤ 10^{5}$

$0 ≤ A_{i} ≤ 2^{31}-1$

$1 ≤ X ≤ N$

$0 ≤ V ≤ 2^{31}-1$

The sum of $N$ over all test cases does not exceed $10^{5}$

The sum of $Q$ over all test cases does not exceed $10^{5}$

----- Sample Input 1 ------ 
2
3 2
1 2 3
1 4
3 0
4 1
1 2 3 4
4 0
----- Sample Output 1 ------ 
3
7
6
7
3
----- explanation 1 ------ 
Example case 1: For the original array, all possible subarrays and their scores are as follows.

$AND(1) = 1$, $AND(2) = 2$, $AND(3) = 3$, $AND(1,2) = 0$, $AND(2,3) = 2$, $AND(1,2,3) = 0$.

The bitwise OR of all possible subarray's score is $OR(1,2,3,0,2,0) = 3$.

After the first query new array will be $[4,2,3]$ and the answer will be $7$.

After the second query new array will be $[4,2,0]$ and the answer will be $6$.

Source: codechef | Difficulty: MEDIUM_HARD


Solutions:
from collections import defaultdict

def cal(d):
	ans = 0
	for i in d:
		if d[i]:
			ans += 2 ** i
	return ans
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = defaultdict(lambda : 0)
	for i in l:
		for j in range(32):
			b = i >> j & 1
			if b:
				d[j] += 1
	print(cal(d))
	for i in range(k):
		(bb, a) = map(int, input().split())
		for j in range(32):
			b = l[bb - 1] >> j & 1
			if b:
				d[j] -= 1
		for j in range(32):
			b = a >> j & 1
			if b:
				d[j] += 1
		l[bb - 1] = a
		print(cal(d))


for _ in range(int(input())):
	(n, q) = map(int, input().split())
	a = [*map(int, input().split())]
	ans = 0
	w = [0] * 32
	for i in a:
		ans |= i
		p = 0
		while i:
			w[p] += i & 1
			i >>= 1
			p += 1
	print(ans)
	for i in range(q):
		(x, v) = map(int, input().split())
		j = a[x - 1]
		a[x - 1] = v
		p = 0
		while j or v:
			w[p] += (v & 1) - (j & 1)
			j >>= 1
			v >>= 1
			p += 1
		ans = 0
		for j in range(32):
			if w[j]:
				ans += 1 << j
		print(ans)


def Build(p, l, r):
	if l == r:
		st[p] = x[l]
		return
	m = (l + r) // 2
	Build(2 * p, l, m)
	Build(2 * p + 1, m + 1, r)
	st[p] = st[2 * p] | st[2 * p + 1]

def Update(p, l, r, i):
	if l == r:
		st[p] = x[l]
		return
	m = (l + r) // 2
	if i <= m:
		Update(2 * p, l, m, i)
	else:
		Update(2 * p + 1, m + 1, r, i)
	st[p] = st[2 * p] | st[2 * p + 1]

def solve():
	(N, Q) = map(int, input().split())
	global x, st
	x = list(map(int, input().split()))
	st = [0] * (4 * N + 1)
	Build(1, 0, N - 1)
	print(st[1])
	while Q != 0:
		(i, v) = map(int, input().split())
		x[i - 1] = v
		Update(1, 0, N - 1, i - 1)
		Q -= 1
		print(st[1])

def main():
	T = int(input())
	while T > 0:
		solve()
		T = T - 1
main()


t = int(input())
for _ in range(t):
	(n, q) = map(int, input().split())
	L = list(map(int, input().split()))
	ans = 0
	A = [0] * 31
	for i in range(n):
		ans |= L[i]
		for j in range(31):
			if 1 << j & L[i]:
				A[j] += 1
	print(ans)
	for k in range(q):
		(x, v) = map(int, input().split())
		for i in range(31):
			if 1 << i & L[x - 1]:
				A[i] -= 1
		for i in range(31):
			if 1 << i & v:
				A[i] += 1
		L[x - 1] = v
		ans = 0
		for i in range(31):
			if A[i]:
				ans += 1 << i
		print(ans)


t = int(input())
while t > 0:
	t -= 1
	ip = input().split()
	(n, q) = [int(i) for i in ip]
	ip = input().split()
	a = [int(i) for i in ip]
	tab = [0 for i in range(31)]
	ores = 0
	for i in a:
		ores = ores | i
		operand = 1
		for j in range(31):
			if i & operand == operand:
				tab[j] += 1
			operand = operand << 1
	print(ores)
	for i in range(q):
		ip = input().split()
		(x, v) = [int(j) for j in ip]
		x -= 1
		operand = 1
		ans = 0
		for j in range(31):
			if a[x] & operand == operand:
				tab[j] -= 1
			if v & operand == operand:
				tab[j] += 1
			if tab[j] >= 1:
				ans = ans | operand
			operand = operand << 1
		a[x] = v
		print(ans)


def calculate(b):
	ans = 0
	for j in range(0, 32, 1):
		if b[j] >= 1:
			ans = ans | 1 << j
	return ans
T = int(input())
for tc in range(0, T):
	(n, q) = map(int, input().split())
	a = list(map(int, input().strip().split()))[:n]
	b = []
	for i in range(0, 32, 1):
		b.append(0)
	for i in range(0, n, 1):
		for j in range(0, 32, 1):
			if a[i] >> j & 1 == 1:
				b[j] += 1
	ans = calculate(b)
	print(ans)
	while q > 0:
		(x, v) = map(int, input().split())
		for j in range(0, 32, 1):
			if a[x - 1] >> j & 1 == 1:
				b[j] -= 1
			if v >> j & 1 == 1:
				b[j] += 1
		a[x - 1] = v
		ans = calculate(b)
		print(ans)
		q -= 1


T = int(input())

def editt(x, ext):
	base = 1
	for i in range(32):
		if x & base:
			freq[i] += ext
		base *= 2

def cal():
	ans = 0
	base = 1
	for i in range(32):
		if freq[i] > 0:
			ans += base
		base *= 2
	return ans
while T > 0:
	T -= 1
	(N, Q) = map(int, input().split())
	lst = list(map(int, input().split()))
	freq = [0] * 32
	for i in lst:
		editt(i, 1)
	print(cal())
	while Q > 0:
		Q -= 1
		(x, v) = map(int, input().split())
		editt(lst[x - 1], -1)
		editt(v, 1)
		lst[x - 1] = v
		print(cal())


def find(l):
	summ = 0
	for i in range(50):
		summ += 2 ** i * min(1, l[i])
	return summ
for _ in range(int(input())):
	(n, q) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	arr = [0 for i in range(50)]
	for x in l:
		i = 0
		while x != 0:
			arr[i] += x & 1
			x = x >> 1
			i += 1
	print(find(arr))
	for qq in range(q):
		(ind, val) = list(map(int, input().split()))
		x = l[ind - 1]
		i = 0
		while x != 0:
			arr[i] -= x & 1
			x = x >> 1
			i += 1
		i = 0
		x = val
		while x != 0:
			arr[i] += x & 1
			x = x >> 1
			i += 1
		l[ind - 1] = val
		print(find(arr))


T = int(input())
for i in range(T):
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	l = len(bin(max(a))) - 2
	r = [0] * 31
	for i in a:
		s = i
		j = 0
		while s:
			r[j] += s & 1
			s >>= 1
			j += 1
	ans = ''
	for i in r:
		if i > 0:
			ans = '1' + ans
		else:
			ans = '0' + ans
	print(int(ans, 2))
	for i in range(q):
		(x, v) = map(int, input().split())
		j = 0
		w = a[x - 1]
		while w:
			r[j] -= w & 1
			w >>= 1
			j += 1
		a[x - 1] = v
		j = 0
		while v:
			r[j] += v & 1
			v >>= 1
			j += 1
		ans = ''
		for i in r:
			if i > 0:
				ans = '1' + ans
			else:
				ans = '0' + ans
		print(int(ans, 2))


for t in range(int(input())):
	(n, q) = tuple(map(int, input().strip().split()))
	a = list(map(int, input().strip().split()))
	dp = [0 for i in range(31)]
	ans = 0
	for v in a:
		b = 1
		for i in range(31):
			if b & v:
				dp[i] += 1
			b <<= 1
		ans |= v
	print(ans)
	for i in range(q):
		(x, v) = tuple(map(int, input().strip().split()))
		c = a[x - 1] ^ v
		b = 1
		for i in range(31):
			if c & b:
				if b & v:
					ans |= b
					dp[i] += 1
				else:
					dp[i] -= 1
					if dp[i] == 0:
						ans -= b
			b <<= 1
		a[x - 1] = v
		print(ans)


for _ in range(int(input())):
	(n, q) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	l = [0] * 32
	for i in range(n):
		for j in range(32):
			if 1 << j & a[i]:
				l[31 - j] += 1
	res = int(''.join((str(1 if i > 0 else 0) for i in l)), 2)
	print(res)
	for _ in range(q):
		(ind, v) = list(map(int, input().split()))
		for j in range(32):
			if 1 << j & a[ind - 1]:
				l[31 - j] -= 1
			if 1 << j & v:
				l[31 - j] += 1
		a[ind - 1] = v
		res = int(''.join((str(1 if i > 0 else 0) for i in l)), 2)
		print(res)


import numpy as np
for i in range(int(input())):
	(n, q) = map(int, input().split())
	ai = np.array([[int(ik) for ik in np.binary_repr(int(ii), width=32)] for ii in input().split()])
	xx = np.sum(ai, axis=0)
	print(sum((xx != 0) * 2 ** np.array(list(range(32)))[::-1]))
	for iii in range(q):
		(x, v) = map(int, input().split())
		xxa = np.array([int(ik) for ik in np.binary_repr(v, width=32)])
		xx = xx + xxa - ai[x - 1]
		ai[x - 1] = xxa
		print(sum((xx != 0) * 2 ** np.array(list(range(32)))[::-1]))


def add(a, b):
	return a | b

class SegmentTree:

	def __init__(self, data, default=0, func=max):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		start += self._size
		stop += self._size
		res_left = res_right = self._default
		while start < stop:
			if start & 1:
				res_left = self._func(res_left, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res_right = self._func(self.data[stop], res_right)
			start >>= 1
			stop >>= 1
		return self._func(res_left, res_right)

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
for i in range(int(input())):
	(n, m) = map(int, input().strip().split())
	lst = list(map(int, input().strip().split()))
	st = SegmentTree(lst, func=add)
	print(st.query(0, n))
	for i in range(m):
		(ind, val) = map(int, input().strip().split())
		st.__setitem__(ind - 1, val)
		lst[ind - 1] = val
		print(st.query(0, n))


from sys import stdin
ip = stdin.readline
for _ in range(int(ip())):
	(n, q) = map(int, ip().split())
	a = list(map(int, ip().split()))
	tobin = lambda x: bin(x).replace('0b', '')[::-1]
	bit = [0] * 31
	for v in a:
		binary = tobin(v)
		for (i, binval) in enumerate(binary):
			bit[i] += int(binval)

	def ans():
		f = 1
		res = 0
		for i in range(31):
			if bit[i]:
				res += f
			f *= 2
		return res
	print(ans())
	for _ in range(q):
		(x, v) = map(int, ip().split())
		x -= 1
		old = tobin(a[x])
		a[x] = v
		for (i, binval) in enumerate(old):
			bit[i] -= int(binval)
		new = tobin(v)
		for (i, val) in enumerate(new):
			bit[i] += int(val)
		print(ans())


def increment(bin_arr, v):
	rev_bin = bin(v)[:1:-1]
	for (i, e) in enumerate(rev_bin):
		bin_arr[i] += int(e)

def decrement(bin_arr, v):
	rev_bin = bin(v)[:1:-1]
	for (i, e) in enumerate(rev_bin):
		bin_arr[i] -= int(e)

def get_int(bin_arr):
	bin_str = '0b' + ''.join(['1' if x > 0 else '0' for x in bin_arr])[::-1]
	return int(bin_str, 2)
for _ in range(int(input())):
	(n, q) = map(int, input().split())
	arr = list(map(int, input().split()))
	bin_arr = [0] * 32
	for v in arr:
		increment(bin_arr, v)
	print(get_int(bin_arr))
	for i in range(q):
		(x, v) = map(int, input().split())
		decrement(bin_arr, arr[x - 1])
		increment(bin_arr, v)
		arr[x - 1] = v
		print(get_int(bin_arr))


for t in range(int(input())):
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	store = {}
	for i in a:
		x = i
		p = 0
		while x:
			if x % 2 == 1:
				if p not in store:
					store[p] = 0
				store[p] += 1
			p += 1
			x //= 2
	ans = 0
	for i in store:
		ans += pow(2, i)
	print(ans)
	for i in range(q):
		(x, y) = map(int, input().split())
		z = x
		x = a[x - 1]
		a[z - 1] = y
		p = 0
		while x:
			if x % 2 == 1:
				store[p] -= 1
				if store[p] == 0:
					store.pop(p)
					ans -= pow(2, p)
			x //= 2
			p += 1
		p = 0
		while y:
			if y % 2 == 1:
				if p not in store:
					store[p] = 0
					ans += pow(2, p)
				store[p] += 1
			p += 1
			y //= 2
		print(ans)


def calc(setbits):
	res = 0
	for i in range(32):
		if setbits[i] > 0:
			res += 2 ** i
	return res
for _ in range(int(input())):
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	setbits = [0] * 32
	for i in a:
		k = 0
		while i != 0:
			setbits[k] += 1 if i & 1 == 1 else 0
			k += 1
			i = i >> 1
	print(calc(setbits))
	for i in range(q):
		(x, v) = map(int, input().split())
		k = 0
		old = a[x - 1]
		a[x - 1] = v
		while old != 0:
			setbits[k] -= 1 if old & 1 == 1 else 0
			old = old >> 1
			k += 1
		k = 0
		while v != 0:
			setbits[k] += 1 if v & 1 == 1 else 0
			v = v >> 1
			k += 1
		print(calc(setbits))


for _ in range(int(input())):
	(n, q) = map(int, input().split())
	ele = list(map(int, input().split()))
	arr = [0] * 31
	ans = 0
	for i in range(n):
		ans |= ele[i]
		for j in range(31):
			if 1 << j & ele[i]:
				arr[j] += 1
	print(ans)
	for _ in range(q):
		(x, v) = map(int, input().split())
		for i in range(31):
			if 1 << i & ele[x - 1]:
				arr[i] -= 1
		for i in range(31):
			if 1 << i & v:
				arr[i] += 1
		ele[x - 1] = v
		ans = 0
		for i in range(31):
			if arr[i] > 0:
				ans += 1 << i
		print(ans)


def binary(b):
	s = ''
	for i in b:
		if i > 0:
			s += '1'
		else:
			s += '0'
	return int(s[::-1], 2)
try:
	t = int(input())
	while t:
		t -= 1
		(n, q) = map(int, input().split())
		lis = list(map(int, input().split()))
		bits = [0] * 35
		for i in lis:
			index = 0
			while i:
				bits[index] += i & 1
				index += 1
				i >>= 1
		print(binary(bits))
		for k in range(q):
			(x, v) = map(int, input().split())
			n = lis[x - 1]
			index = 0
			while n:
				bits[index] -= n & 1
				index += 1
				n >>= 1
			lis[x - 1] = v
			index = 0
			while v:
				bits[index] += v & 1
				index += 1
				v >>= 1
			print(binary(bits))
except:
	pass


def f(A):
	s = [0] * 32
	for i in range(31):
		for j in range(len(A)):
			if A[j] & 1 << i > 0:
				s[i] += 1
	return s

def sm(s):
	x = 0
	mul = 1
	for i in range(31):
		x += mul if s[i] else 0
		mul = mul << 1
	print(x)
for i in range(int(input())):
	(n, q) = map(int, input().split())
	l = list(map(int, input().split()))
	s = f(l)
	sm(s)
	for a in range(q):
		(r, r2) = map(int, input().split())
		r1 = l[r - 1]
		for i in range(31):
			if r1 & 1 << i:
				s[i] -= 1
			if r2 & 1 << i:
				s[i] += 1
		l[r - 1] = r2
		sm(s)


import math
t = int(input())
for _ in range(t):
	(n, q) = map(int, input().split())
	nos = list(map(int, input().split()))
	ans = {i: 0 for i in range(32)}
	for i in range(len(nos)):
		nos[i] = '{:032b}'.format(nos[i])
		j = 0
		for k in range(31, -1, -1):
			if nos[i][k] == '1':
				ans[j] += 1
			j += 1
	tempans = 0
	for bit in ans:
		if ans[bit] > 0:
			tempans += 2 ** bit
	print(tempans)
	for query in range(q):
		(x, v) = map(int, input().split())
		x -= 1
		j = 0
		for k in range(31, -1, -1):
			if nos[x][k] == '1':
				ans[j] -= 1
			j += 1
		nos[x] = '{:032b}'.format(v)
		j = 0
		for k in range(31, -1, -1):
			if nos[x][k] == '1':
				ans[j] += 1
			j += 1
		tempans = 0
		for bit in ans:
			if ans[bit] >= 1:
				tempans += 2 ** bit
		print(tempans)


for _ in range(int(input())):
	(n, Q) = map(int, input().split(' '))
	A = list(map(int, input().split(' ')))
	D = {}
	S = 0
	for a in A:
		S |= a
		for (s, i) in enumerate(bin(a)[2:][::-1]):
			if i == '1':
				D[s] = D.get(s, 0) + 1
	print(S)
	for q in range(Q):
		(x, v) = map(int, input().split(' '))
		S |= v
		for (s, i) in enumerate(bin(v)[2:][::-1]):
			if i == '1':
				D[s] = D.get(s, 0) + 1
		for (s, i) in enumerate(bin(A[x - 1])[2:][::-1]):
			if i == '1':
				h = D[s]
				D[s] = h - 1
				if h == 1:
					S -= 1 << s
		A[x - 1] = v
		print(S)


T = int(input())
while T:
	T -= 1
	(N, Q) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	freq = [0] * 33
	for i in A:
		bit = 0
		while i >= 1:
			if i % 2 != 0:
				freq[bit] += 1
			i = i // 2
			bit += 1
	ors = 0
	for i in range(0, 33):
		if freq[i] > 0:
			ors += 2 ** i
	print(ors)
	while Q:
		Q -= 1
		(X, V) = [int(x) for x in input().split()]
		X -= 1
		bit = 0
		while A[X] >= 1:
			if A[X] % 2 != 0:
				freq[bit] -= 1
			A[X] = A[X] // 2
			bit += 1
		A[X] = V
		bit = 0
		while V >= 1:
			if V % 2 != 0:
				freq[bit] += 1
			V = V // 2
			bit += 1
		ors = 0
		for i in range(0, len(freq)):
			if freq[i] > 0:
				ors += 2 ** i
		print(ors)


from itertools import accumulate
t = int(input())
for _ in range(t):
	(n, q) = map(int, input().split())
	nums = list(map(lambda x: bin(int(x))[2:].zfill(31), input().split()))
	queries = [list(map(int, input().split())) for _ in range(q)]
	count = [0 for _ in range(31)]
	for num in nums:
		count = list(map(lambda x: x[1] + int(x[0]), zip(num, count)))
	print(list(accumulate(map(lambda x: x > 0, count), lambda tot, x: 2 * tot + x))[-1])
	for query in queries:
		count = list(map(lambda x: x[1] - int(x[0]), zip(nums[query[0] - 1], count)))
		nums[query[0] - 1] = bin(query[1])[2:].zfill(31)
		count = list(map(lambda x: x[1] + int(x[0]), zip(nums[query[0] - 1], count)))
		print(list(accumulate(map(lambda x: x > 0, count), lambda tot, x: 2 * tot + x))[-1])


t = int(input())
for _ in range(t):
	(n, q) = map(int, input().split())
	arr = list(map(int, input().split()))
	bit = [0] * 31
	for num in arr:
		count = 0
		while num != 0:
			bit[count] += 1 if num & 1 == 1 else 0
			num = num >> 1
			count += 1
	ans = 0
	for i in range(31):
		if bit[i] > 0:
			ans += 2 ** i
	print(ans)
	for z in range(q):
		(x, v) = map(int, input().split())
		old = arr[x - 1]
		arr[x - 1] = v
		count = 0
		while old != 0:
			bit[count] -= 1 if old & 1 == 1 else 0
			old = old >> 1
			count += 1
		count = 0
		while v != 0:
			bit[count] += 1 if v & 1 == 1 else 0
			v = v >> 1
			count += 1
		ans = 0
		for i in range(31):
			if bit[i] > 0:
				ans += 2 ** i
		print(ans)


T = int(input())
for i in range(T):
	(N, Q) = map(int, input().split())
	A = list(map(int, input().split()))
	ans = [0] * 31
	for bit in range(31):
		for i in range(N):
			if A[i] & 1 << bit:
				ans[bit] += 1
	res = 0
	for bit in range(31):
		if ans[bit] > 0:
			res += 2 ** bit
	print(res)
	for qr in range(Q):
		res = 0
		(X, V) = map(int, input().split())
		for bit in range(31):
			if A[X - 1] & 1 << bit:
				ans[bit] -= 1
			if V & 1 << bit:
				ans[bit] += 1
		A[X - 1] = V
		for bit in range(31):
			if ans[bit] > 0:
				res += 2 ** bit
		print(res)


from functools import reduce
t = int(input())

def tobinary(num):
	mul = 1
	f = 0
	while num > 0:
		res = num % 2
		num = num // 2
		f = f + mul * res
		mul = mul * 10
	return str(f)

def todecimal(num):
	res = 0
	j = 0
	for i in num:
		res = res + 2 ** j * int(i)
		j += 1
	return res

def getValue(freq):
	ans = 0
	b = 1
	for i in range(32):
		if freq[i] >= 1:
			ans += b
		b *= 2
	return ans
for z in range(t):
	(n, m) = list(input().split())
	n = int(n)
	m = int(m)
	l = list(map(int, input().split()))
	fre = [0] * 32
	q = []
	for i in range(m):
		q.append(list(map(int, input().split())))
	for i in l:
		res = tobinary(i)
		for j in range(len(res) - 1, -1, -1):
			fre[len(res) - j - 1] = fre[len(res) - j - 1] + int(res[j])
	print(getValue(fre))
	for k in q:
		res = tobinary(l[k[0] - 1])
		for j in range(len(res) - 1, -1, -1):
			fre[len(res) - j - 1] = fre[len(res) - j - 1] - int(res[j])
		res = tobinary(k[1])
		for j in range(len(res) - 1, -1, -1):
			fre[len(res) - j - 1] = fre[len(res) - j - 1] + int(res[j])
		l[k[0] - 1] = k[1]
		print(getValue(fre))


c = int(input())
while c:

	def ans(arra):
		an = 0
		for i in range(50):
			an += 2 ** i * min(arra[i], 1)
		return an
	c -= 1
	(n, q) = map(int, input().split())
	l = list(map(int, input().split()))
	arr = [0 for i in range(50)]
	for j in l:
		i = 0
		while j != 0:
			arr[i] += j & 1
			j = j >> 1
			i += 1
	print(ans(arr))
	for h in range(q):
		(pi, np) = map(int, input().split())
		p = l[pi - 1]
		l[pi - 1] = np
		i = 0
		while p != 0:
			arr[i] -= p & 1
			p = p >> 1
			i += 1
		i = 0
		while np != 0:
			arr[i] += np & 1
			np = np >> 1
			i += 1
		print(ans(arr))


powers = [1]
for i in range(1, 32):
	powers.append(powers[-1] * 2)

def decimal(a):
	ans = 0
	for i in range(32):
		ans += powers[i] * (1 if a[i] != 0 else 0)
	return ans

def solve():
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	b = [0 for i in range(32)]
	for i in a:
		c = 0
		while i != 0:
			b[c] += i % 2
			i = i // 2
			c += 1
	print(decimal(b))
	while q != 0:
		(x, v) = map(int, input().split())
		actual = a[x - 1]
		c = 0
		while actual != 0:
			b[c] -= actual % 2
			actual = actual // 2
			c += 1
		a[x - 1] = v
		c = 0
		while v != 0:
			b[c] += v % 2
			v = v // 2
			c += 1
		print(decimal(b))
		q -= 1
for _ in range(int(input())):
	solve()


t = int(input())
for i in range(t):
	(n, q) = map(int, input().split())
	k = list(map(int, input().split()))
	bin_arr = [0] * 32
	for u in k:
		result = bin(u)[2:]
		rev = result[::-1]
		for g in range(len(rev)):
			if rev[g] == '1':
				bin_arr[31 - g] += 1
	s = ''
	for u in bin_arr:
		if u != 0:
			s += '1'
		else:
			s += '0'
	print(int(s, 2))
	for j in range(q):
		(x, v) = map(int, input().split())
		result = bin(k[x - 1])[2:]
		k[x - 1] = v
		rev = result[::-1]
		for g in range(len(result)):
			if rev[g] == '1':
				bin_arr[31 - g] -= 1
		result = bin(v)[2:]
		rev = result[::-1]
		for g in range(len(result)):
			if rev[g] == '1':
				bin_arr[31 - g] += 1
		s = ''
		for g in bin_arr:
			if g != 0:
				s += '1'
			else:
				s += '0'
		print(int(s, 2))


def fxn1(bits, num):
	for i in range(len(bits) - 1, -1, -1):
		bits[i] += num & 1
		num = num >> 1
	return bits

def fxn2(bits, num):
	for i in range(len(bits) - 1, -1, -1):
		bits[i] -= num & 1
		num = num >> 1
	return bits

def b2d(bits):
	dec = 0
	power = 0
	for i in range(len(bits) - 1, -1, -1):
		dec += min(1, bits[i]) * 2 ** power
		power += 1
	return dec
t = int(input())
for i in range(t):
	(n, q) = map(int, input().split())
	arr = list(map(int, input().split()))
	bits = [0] * 31
	for i in arr:
		bits = fxn1(bits, i)
	print(b2d(bits))
	for j in range(q):
		(ind, val) = map(int, input().split())
		bits = fxn2(bits, arr[ind - 1])
		arr[ind - 1] = val
		bits = fxn1(bits, val)
		print(b2d(bits))


for _ in range(int(input())):
	(n, q) = map(int, input().split())
	l = [int(x) for x in input().split()]
	ans = 0
	ans = [0] * 32
	for item in l:
		result = bin(item)[2:]
		count = len(result)
		for i in range(count):
			if result[i] == '1':
				ans[count - 1 - i] += 1
	s = ''
	for i in ans:
		if i != 0:
			s = '1' + s
		else:
			s = '0' + s
	print(int(s, 2))
	for i in range(q):
		(index, value) = map(int, input().split())
		result = l[index - 1]
		l[index - 1] = value
		result = bin(result)[2:]
		count = len(result)
		for i in range(count):
			if result[i] == '1':
				ans[count - 1 - i] -= 1
		result = bin(value)[2:]
		count = len(result)
		for i in range(count):
			if result[i] == '1':
				ans[count - 1 - i] += 1
		s = ''
		for i in ans:
			if i != 0:
				s = '1' + s
			else:
				s = '0' + s
		print(int(s, 2))


def getFreq(freq, val, z):
	b = 1
	for i in range(32):
		if b & val:
			freq[i] += z
		b *= 2

def getValue(freq):
	ans = 0
	b = 1
	for i in range(32):
		if freq[i]:
			ans += b
		b *= 2
	return ans
for _ in range(int(input())):
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	freq = [0] * 32
	for num in a:
		getFreq(freq, num, 1)
	print(getValue(freq))
	for i in range(q):
		(x, v) = map(int, input().split())
		getFreq(freq, a[x - 1], -1)
		getFreq(freq, v, 1)
		a[x - 1] = v
		print(getValue(freq))


t = int(input())
for i in range(0, t):
	arr = list(map(int, input().strip().split()))
	N = arr[0]
	Q = arr[1]
	A = list(map(int, input().strip().split()))
	freq = [0] * 32
	for m in range(0, N):
		st_binary = str(bin(A[m]).replace('0b', ''))
		st_binary = st_binary[::-1]
		for n in range(0, len(st_binary)):
			if st_binary[n] == '1':
				freq[n] += 1
	st = ''
	for m in range(0, 32):
		if freq[m] == 0:
			st += '0'
		else:
			st += '1'
	st = st[::-1]
	no = int(st, 2)
	print(no)
	for j in range(0, Q):
		arr1 = list(map(int, input().strip().split()))
		X = arr1[0]
		V = arr1[1]
		val1 = A[X - 1]
		val2 = V
		A[X - 1] = V
		st_binary_sub = str(bin(val1).replace('0b', ''))
		st_binary_sub = st_binary_sub[::-1]
		st_binary_add = str(bin(val2).replace('0b', ''))
		st_binary_add = st_binary_add[::-1]
		for k in range(32):
			if k < len(st_binary_sub) and st_binary_sub[k] == '1':
				freq[k] -= 1
			if k < len(st_binary_add) and st_binary_add[k] == '1':
				freq[k] += 1
		st = ''
		for m in range(0, 32):
			if freq[m] == 0:
				st += '0'
			else:
				st += '1'
		st = st[::-1]
		no = int(st, 2)
		print(no)


from math import ceil, log2
for tc in range(int(input())):
	(N, Q) = map(int, input().split())
	A = list(map(int, input().split()))
	bits = [0] * 31
	OR = 0
	for i in A:
		OR |= i
		if i != 0:
			blen = len(bin(i)[2:])
			for j in range(blen):
				if i & 1 << j:
					bits[30 - j] += 1
	print(OR)
	for q in range(Q):
		QOR = ''
		(X, V) = map(int, input().split())
		X -= 1
		blen = len(bin(A[X])[2:])
		for j in range(blen):
			if A[X] & 1 << j:
				bits[30 - j] -= 1
		A[X] = V
		blen = len(bin(A[X])[2:])
		if A[X] != 0:
			for j in range(blen):
				if A[X] & 1 << j:
					bits[30 - j] += 1
		for b in bits:
			if b > 0:
				QOR += '1'
				continue
			QOR += '0'
		print(int(QOR, 2))


t = int(input())
for _ in range(0, t):
	(n, q) = map(int, input().split())
	list_n = list(map(int, input().split()))
	bit = [0] * 32
	for i in range(0, n):
		for j in range(0, 32):
			if 1 << j & list_n[i]:
				bit[j] += 1
	ans = 0
	for i in range(0, 32):
		if bit[i]:
			ans += 1 << i
	print(ans)
	for k in range(0, q):
		ans = 0
		(pos, val) = map(int, input().split())
		for i in range(0, 32):
			if 1 << i & list_n[pos - 1]:
				bit[i] -= 1
		for i in range(0, 32):
			if 1 << i & val:
				bit[i] += 1
		list_n[pos - 1] = val
		for i in range(0, 32):
			if bit[i]:
				ans += 1 << i
		print(ans)


import sys
I = lambda : int(sys.stdin.readline())
In = lambda : list(map(int, sys.stdin.readline().split()))
pr = lambda x: sys.stdout.write(str(x) + '\n')

def solve():
	(n, q) = In()
	a = In()
	val = [0] * 32
	for v in a:
		for i in range(32):
			c = 1 << i
			if v & c:
				val[i] += 1
				if c > v:
					break
	ans = array_to_int(val)
	pr(ans)
	while q:
		q -= 1
		(pos, new_val) = In()
		pos -= 1
		v = a[pos]
		a[pos] = new_val
		for i in range(32):
			c = 1 << i
			if v & c:
				val[i] -= 1
			if new_val & c:
				val[i] += 1
		pr(array_to_int(val))

def array_to_int(a):
	b = [1 if i > 0 else 0 for i in a]
	s = ''.join([str(i) for i in b[::-1]])
	return int(s, 2)
for _ in range(I()):
	solve()


def solve():
	(n, q) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	val = [0] * 32
	for v in a:
		for i in range(32):
			c = 1 << i
			if v & c:
				val[i] += 1
				if c > v:
					break
	ans = array_to_int(val)
	print(ans)
	while q:
		q -= 1
		(pos, new_val) = [int(x) for x in input().split()]
		pos -= 1
		v = a[pos]
		a[pos] = new_val
		for i in range(32):
			c = 1 << i
			if v & c:
				val[i] -= 1
			if new_val & c:
				val[i] += 1
		print(array_to_int(val))

def array_to_int(a):
	b = [1 if i > 0 else 0 for i in a]
	s = ''.join([str(i) for i in b[::-1]])
	return int(s, 2)
for _ in range(int(input())):
	solve()


import sys
I = lambda : int(sys.stdin.readline())
In = lambda : list(map(int, sys.stdin.readline().split()))
pr = lambda x: sys.stdout.write(str(x) + '\n')

def main():
	T = I()
	bits = [1]
	for i in range(1, 32):
		bits.append(bits[-1] * 2)
	for t in range(T):
		(n, q) = In()
		A = In()
		dp = [0] * 32
		for x in A:
			j = 0
			while x > 0:
				if x & 1 > 0:
					dp[j] += 1
				x >>= 1
				j += 1
		ans = 0
		for i in range(32):
			if dp[i] > 0:
				ans += bits[i]
		pr(ans)
		for k in range(q):
			(idx, v) = In()
			j = 0
			x = A[idx - 1]
			while x:
				if x & 1:
					dp[j] -= 1
				x >>= 1
				j += 1
			A[idx - 1] = v
			j = 0
			while v:
				if v & 1:
					dp[j] += 1
				v >>= 1
				j += 1
			ans = 0
			for i in range(32):
				if dp[i] > 0:
					ans += bits[i]
			pr(ans)
main()


t = int(input())
for _ in range(t):
	bits = [0 for i in range(32)]
	(n, q) = map(int, input().split())
	a = [int(i) for i in input().split()]
	for i in a:
		i = bin(i)[2:]
		for j in range(1, len(i) + 1):
			if i[-j] == '1':
				bits[-j] += 1
	nums = []
	for i in bits:
		if i > 0:
			nums.append('1')
		else:
			nums.append('0')
	nums = ''.join(nums)
	nums = int(nums, 2)
	print(nums)
	for _ in range(q):
		(x, v) = map(int, input().split())
		i = bin(a[x - 1])[2:]
		for j in range(1, len(i) + 1):
			if i[-j] == '1':
				bits[-j] -= 1
		i = bin(v)[2:]
		for j in range(1, len(i) + 1):
			if i[-j] == '1':
				bits[-j] += 1
		a[x - 1] = v
		nums = []
		for i in bits:
			if i > 0:
				nums.append('1')
			else:
				nums.append('0')
		nums = ''.join(nums)
		nums = int(nums, 2)
		print(nums)


def oraplus(temp):
	bit = 0
	while temp > 0:
		if temp % 2 == 1:
			ora[bit] += 1
		bit += 1
		temp //= 2

def oraminus(temp):
	bit = 0
	while temp > 0:
		if temp % 2 == 1:
			ora[bit] -= 1
		bit += 1
		temp //= 2

def calans():
	ans = 0
	num = 1
	for i in range(0, 33):
		if ora[i] > 0:
			ans += num
		num *= 2
	return ans

def calor(a):
	global ora
	for x in a:
		temp = x
		oraplus(temp)
	return calans()
for _ in range(int(input())):
	ora = [0] * 33
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	print(calor(a))
	for _ in range(q):
		(index, e) = map(int, input().split())
		temp = a[index - 1]
		a[index - 1] = e
		oraminus(temp)
		oraplus(e)
		print(calans())


def main():
	T = int(input())
	for _ in range(T):
		(N, Q) = map(int, input().split())
		A = list(map(int, input().split()))
		bitArr = [0] * 31
		ans = 0
		for i in range(N):
			temp = A[i]
			c = 0
			while temp > 0:
				if temp % 2 != 0:
					bitArr[c] += 1
				temp = temp // 2
				c += 1
			ans = ans | A[i]
		print(ans)
		for _ in range(Q):
			(X, V) = map(int, input().split())
			for b in range(31):
				if A[X - 1] & 1 << b != 0 and V & 1 << b == 0:
					bitArr[b] -= 1
				elif A[X - 1] & 1 << b == 0 and V & 1 << b != 0:
					bitArr[b] += 1
			ans = 0
			for b in range(31):
				if bitArr[b] != 0:
					ans += 1 << b
			A[X - 1] = V
			print(ans)
main()


t = int(input())
for _ in range(t):
	nq = input().split()
	n = int(nq[0])
	q = int(nq[1])
	arr = list(map(int, input().split()))
	bit = [0] * 32
	for i in range(n):
		for j in range(32):
			if 1 << j & arr[i]:
				bit[j] += 1
	ans = 0
	for j in range(32):
		if bit[j]:
			ans += 1 << j
	print(ans)
	for i in range(q):
		xv = input().split()
		x = int(xv[0])
		v = int(xv[1])
		for j in range(32):
			if 1 << j & arr[x - 1]:
				bit[j] -= 1
		for j in range(32):
			if 1 << j & v:
				bit[j] += 1
		arr[x - 1] = v
		ans = 0
		for j in range(32):
			if bit[j]:
				ans += 1 << j
		print(ans)


def frequency(f, v, e):
	base = 1
	for i in range(31, -1, -1):
		if v & base:
			f[i] += e
		base *= 2
t = int(input())
while t:
	(n, q) = map(int, input().split())
	l = list(map(int, input().split()))
	f = [0] * 32
	for i in l:
		frequency(f, i, 1)
	base = 1
	c = 0
	for i in f:
		if i != 0:
			c += 1 * base
			base *= 2
	print(c)
	i = 0
	while i < q:
		(a, b) = map(int, input().split())
		frequency(f, l[a - 1], -1)
		frequency(f, b, 1)
		l[a - 1] = b
		j = 31
		base = 1
		c = 0
		while j >= 0:
			if f[j] != 0:
				c += 1 * base
			base *= 2
			j -= 1
		print(c)
		i += 1
	t -= 1


from collections import Counter
arr = [0] * 32
theta = 0
theta += 1
thetas = [2 ** (31 - i) for i in range(32)]

def add(k):
	bina = bin(k)[2:]
	theta = 0
	theta = 0
	bina = '0' * (32 - len(bina)) + bina
	theta = 0
	for i in range(32):
		theta = 0
		if bina[i] == '1':
			theta = 0
			arr[i] += 1
	theta = 0

def sub(k):
	bina = bin(k)[2:]
	theta = 0
	bina = '0' * (32 - len(bina)) + bina
	theta = 0
	for i in range(32):
		theta = 0
		if bina[i] == '1':
			theta = 0
			arr[i] -= 1

def get_value():
	theta = 0
	suma = 0
	theta = 0
	for i in range(32):
		theta = 0
		suma += thetas[i] * (arr[i] > 0)
		theta = 0
	return suma
theta = 0
t = int(input())
theta = 0
for i in range(t):
	theta = 0
	(n, q) = list(map(int, input().split()))
	theta = 0
	arr = [0] * 32
	theta = 0
	l = list(map(int, input().split()))
	theta = 0
	suma = 0
	theta = 0
	for i in l:
		theta = 0
		add(i)
	theta = 0
	print(get_value())
	theta = 0
	for i in range(q):
		(index, val) = map(int, input().split())
		theta = 0
		index -= 1
		theta = 0
		sub(l[index])
		theta = 0
		l[index] = val
		theta = 0
		add(l[index])
		theta = 0
		print(get_value())
		theta = 0


def binarytodecimal(freq):
	ans = 0
	base = 1
	for i in range(32):
		if freq[i]:
			ans = ans + base
		base *= 2
	print(ans)

def solve(arr, check, freq):
	for i in range(32):
		if arr >> i & 1 == 1:
			freq[i] += check
	return freq

def main():
	t = int(input())
	for t1 in range(t):
		(n, q) = [int(x) for x in input().split()]
		arr = list(map(int, input().split()))[:n]
		freq = [0 for i in range(32)]
		for q1 in range(q + 1):
			if q1 != 0:
				(X, Y) = [int(x) for x in input().split()]
				X -= 1
				freq = solve(arr[X], -1, freq)
				arr[X] = Y
				freq = solve(arr[X], 1, freq)
				binarytodecimal(freq)
			else:
				for i in range(len(arr)):
					freq = solve(arr[i], 1, freq)
				binarytodecimal(freq)
main()


try:
	t = int(input())
	for i in range(0, t):
		(n, q) = map(int, input().split())
		a = list(map(int, input().split()))
		bit = ['0'] * 31
		orr = 0
		kp = []
		for i in range(0, len(a)):
			orr |= a[i]
			k = bin(a[i])
			l = len(k[2:])
			kp.append((31 - l) * '0' + k[2:])
		print(orr)
		for i in range(0, len(kp)):
			for j in range(0, 31):
				if kp[i][j] == '1':
					bit[j] = str(int(bit[j]) + 1)
		for i in range(0, q):
			(p, q) = map(int, input().split())
			up = bin(a[p - 1])
			lk = len(up[2:])
			x = (31 - lk) * '0' + up[2:]
			uq = bin(q)
			lkk = len(uq[2:])
			y = (31 - lkk) * '0' + uq[2:]
			for i in range(0, len(y)):
				if y[i] == '1':
					bit[i] = str(int(bit[i]) + 1)
				if x[i] == '1':
					bit[i] = str(int(bit[i]) - 1)
			np = bit.copy()
			for i in range(0, len(np)):
				if int(np[i]) >= 1:
					np[i] = '1'
			np = ''.join(np)
			npo = int(np, 2)
			print(npo)
			a[p - 1] = q
except:
	pass


for _ in range(int(input())):
	dp = []
	for i in range(32):
		dp.append(0)
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in a:
		p = bin(i).replace('0b', '')
		c = 31
		for j in range(len(p) - 1, -1, -1):
			if p[j] == '1':
				dp[c] += 1
			c -= 1
	m = ''
	for i in dp:
		if i != 0:
			m += '1'
		else:
			m += '0'
	print(int(m, 2))
	for i in range(q):
		(x, v) = map(int, input().split())
		p = bin(a[x - 1]).replace('0b', '')
		c = 31
		for j in range(len(p) - 1, -1, -1):
			if p[j] == '1':
				dp[c] -= 1
			c -= 1
		a[x - 1] = v
		c = 31
		p = bin(v).replace('0b', '')
		for j in range(len(p) - 1, -1, -1):
			if p[j] == '1':
				dp[c] += 1
			c -= 1
		m = ''
		for i in dp:
			if i != 0:
				m += '1'
			else:
				m += '0'
		print(int(m, 2))


def change(elem, act):
	tt = 1
	j = 0
	while j < 32:
		if tt & elem:
			freqy[j] += act
		j += 1
		tt <<= 1

def oreo(qq):
	zz = 0
	for k in range(len(qq)):
		if qq[k]:
			zz += 2 ** k
	return zz
tkk = int(input())
for z in range(tkk):
	tst = 0
	(n, q) = map(int, input().split())
	lt = list(map(int, input().split()))
	freqy = [0] * 32
	for i in range(n):
		tst += 1
		change(lt[i], 1)
	print(oreo(freqy))
	for pp in range(q):
		(x, v) = map(int, input().split())
		change(v, 1)
		change(lt[x - 1], -1)
		lt[x - 1] = v
		print(oreo(freqy))


t = int(input())
for x in range(t):
	(n, q) = map(int, input().split())
	arr = list(map(int, input().split()))
	freq = list()
	for i in range(32):
		freq.append(0)
	for i in range(n):
		temp = bin(arr[i])[2:]
		index = 32 - len(temp)
		for j in range(len(temp)):
			freq[index + j] += int(temp[j])
	result = str()
	for i in range(32):
		if freq[i] > 0:
			result += '1'
	print(int(result, 2))
	for i in range(q):
		(x, y) = map(int, input().split())
		temp = bin(arr[x - 1])[2:]
		index = 32 - len(temp)
		for j in range(len(temp)):
			freq[index + j] -= int(temp[j])
		arr[x - 1] = y
		temp = bin(arr[x - 1])[2:]
		index = 32 - len(temp)
		for j in range(len(temp)):
			freq[index + j] += int(temp[j])
		result = ''
		flag = False
		for j in range(32):
			if (freq[j] > 0) | flag:
				if freq[j] > 0:
					result += '1'
				else:
					result += '0'
				flag = True
		print(int(result, 2))


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

def getBit(elem):
	arr = []
	while elem > 0:
		arr.append(elem % 2)
		elem = elem // 2
	for _ in range(32 - len(arr)):
		arr.append(0)
	arr.reverse()
	return arr

def getNumber(bitArr):
	bitArr.reverse()
	num = 0
	for i in range(len(bitArr)):
		num += bitArr[i] * 2 ** i
	return num

def getBitFromOrArr(orarr):
	a = []
	for e in orarr:
		if e > 0:
			a.append(1)
		else:
			a.append(0)
	return a
t = int(input())
while t > 0:
	t -= 1
	(n, q) = readInput()
	arr = readInput()
	orarr = [0 for _ in range(32)]
	for elem in arr:
		bitArr = getBit(elem)
		for i in range(len(bitArr)):
			orarr[i] += bitArr[i]
	print(getNumber(getBitFromOrArr(orarr)))
	for _ in range(q):
		(x, v) = readInput()
		elemX = arr[x - 1]
		arr[x - 1] = v
		bitArrX = getBit(elemX)
		for i in range(len(bitArrX)):
			orarr[i] -= bitArrX[i]
		bitArrV = getBit(v)
		for i in range(len(bitArrV)):
			orarr[i] += bitArrV[i]
		print(getNumber(getBitFromOrArr(orarr)))


def updateFrequency(num, change):
	bit = f'{num:031b}'
	for i in range(1, 32):
		bitMap[i] += int(bit[i - 1]) * change

def finalScore():
	bin = ''
	for i in range(1, 32):
		digit = 1 if bitMap[i] > 0 else 0
		bin = f'{bin}{digit}'
	return int(bin, 2)

def query():
	(x, v) = map(int, input().split())
	updateFrequency(arr[x - 1], -1)
	updateFrequency(v, 1)
	arr[x - 1] = v
	print(finalScore())
for _ in range(int(input())):
	(n, q) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	bitMap = {i: 0 for i in range(1, 32)}
	for a in arr:
		updateFrequency(a, 1)
	print(finalScore())
	for _ in range(q):
		query()


il = lambda : list(map(int, input().split()))
iin = lambda : map(int, input().split())
ii = lambda : int(input())
for _ in range(ii()):
	(n, q) = iin()
	a = il()
	temp = [0] * 32
	ans = a[0]
	for k in range(1, 32):
		if ans & 1 << k - 1:
			temp[k] += 1
	for i in range(1, n):
		ans |= a[i]
		for k in range(1, 32):
			if a[i] & 1 << k - 1:
				temp[k] += 1
	print(ans)
	for _ in range(q):
		(x, v) = iin()
		t = a[x - 1]
		a[x - 1] = v
		for k in range(1, 32):
			if t & 1 << k - 1:
				temp[k] -= 1
				if temp[k] == 0:
					ans = ans & ~(1 << k - 1)
		for k in range(1, 32):
			if v & 1 << k - 1:
				temp[k] += 1
		ans |= v
		print(ans)


for i in range(int(input())):
	(n, q) = map(int, input().split())
	ar = list(map(int, input().split()))
	arr = [0] * 32
	orr = 0
	for j in ar:
		orr = orr | j
		k = 0
		while j:
			t = j % 2
			j //= 2
			if t == 1:
				arr[k] += 1
			k += 1
	print(orr)
	for j in range(q):
		(a, b) = map(int, input().split())
		k = 0
		b2 = ar[a - 1]
		while b2:
			t = b2 % 2
			b2 //= 2
			if t == 1:
				arr[k] -= 1
			k += 1
		ar[a - 1] = b
		k = 0
		while b:
			t = b % 2
			b //= 2
			if t == 1:
				arr[k] += 1
			k += 1
		summ = 0
		cnt = 0
		for l in arr:
			if l >= 1:
				summ += 2 ** cnt
			cnt += 1
		print(summ)


t = int(input())
for _ in range(t):
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	(arr, ans, ones) = ([], 0, [0] * 32)
	for no in a:
		ans |= no
		b = bin(no)[2:]
		b = b[::-1] + str('0' * (32 - len(b)))
		for i in range(32):
			if b[i] == '1':
				ones[i] += 1
		arr.append(b)
	print(ans)
	for i in range(q):
		(x, v) = map(int, input().split())
		x -= 1
		for j in range(32):
			if arr[x][j] == '1':
				ones[j] -= 1
		v = bin(v)[2:]
		v = v[::-1] + str('0' * (32 - len(v)))
		arr[x] = v
		for j in range(32):
			if v[j] == '1':
				ones[j] += 1
		res = 0
		for j in range(32):
			if ones[j] > 0:
				res += pow(2, j)
		print(res)


for _ in range(int(input())):
	(n, q) = map(int, input().split())
	arr = list(map(int, input().split()))
	l = [0] * 32
	for j in range(n):
		k = arr[j]
		for i in range(31, -1, -1):
			a = 2 ** i
			if a <= k:
				l[i] += 1
				k -= a
	ans = 0
	ct = 1
	for i in range(0, 32):
		if l[i]:
			ans += ct
		ct *= 2
	print(ans)
	for i in range(q):
		(x, v) = map(int, input().split())
		k = arr[x - 1]
		for i in range(31, -1, -1):
			a = 2 ** i
			if a <= k:
				l[i] -= 1
				k -= a
		arr[x - 1] = v
		for i in range(31, -1, -1):
			a = 2 ** i
			if a <= v:
				l[i] += 1
				v -= a
		ans = 0
		ct = 1
		for i in range(0, 32):
			if l[i]:
				ans += ct
			ct *= 2
		print(ans)


import math
read = lambda : list(map(int, input().strip().split()))
rs = lambda : int(input().strip())
t = rs()
ans = []

class seg:

	def __init__(self, a, n):
		self.a = a
		self.na = [0] * n + a
		self.n = n
		self.create()

	def create(self):
		for i in range(self.n - 1, 0, -1):
			self.na[i] = self.na[i << 1] | self.na[i << 1 | 1]

	def modify(self, x, v):
		i = x + self.n
		self.na[i] = v
		while i > 1:
			self.na[i >> 1] = self.na[i] | self.na[i ^ 1]
			i >>= 1

	def query(self, l, r):
		res = 0
		l += self.n
		r += self.n
		while l < r:
			if l & 1:
				res |= self.na[l]
				l += 1
			if r & 1:
				r -= 1
				res |= self.na[r]
			l >>= 1
			r >>= 1
		return res
for i in range(t):
	(nl, ql) = read()
	arr = read()
	st = seg(arr, nl)
	ans.append(st.query(0, nl))
	for _ in range(ql):
		(xl, vl) = read()
		xl -= 1
		if arr[xl] != vl:
			st.modify(xl, vl)
			ans.append(st.query(0, nl))
		else:
			ans.append(st.query(0, nl))
print('\n'.join([str(x) for x in ans]))


def ans(arr):
	res = 0
	for i in range(32):
		if arr[i]:
			res = res + (1 << i)
	return res
for _ in range(int(input())):
	(n, q) = map(int, input().split())
	arr = [int(i) for i in input().split()]
	sb = [0] * 32
	for i in arr:
		for j in range(32):
			if i & 1 << j:
				sb[j] += 1
	print(ans(sb))
	for t0 in range(q):
		(x, y) = map(int, input().split())
		x = x - 1
		tmp = arr[x]
		for j in range(32):
			if tmp & 1 << j:
				sb[j] -= 1
		for j in range(32):
			if y & 1 << j:
				sb[j] += 1
		arr[x] = y
		print(ans(sb))


from functools import reduce
for _ in range(int(input())):
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	dp = [0] * 31
	for i in range(n):
		for j in range(31):
			if a[i] & 1 << j:
				dp[j] += 1
	print(sum([1 << i for i in range(31) if dp[i]]))
	for k in range(q):
		(idx, v) = map(int, input().split())
		for i in range(31):
			if a[idx - 1] & 1 << i:
				dp[i] -= 1
			if v & 1 << i:
				dp[i] += 1
		a[idx - 1] = v
		print(sum([1 << i for i in range(31) if dp[i] > 0]))


import functools
t = int(input())
for i in range(t):
	(n, q) = [int(x) for x in input().split()]
	a = list(map(int, input().split()))
	res = 0
	freq = {}
	for i in range(32):
		freq[i] = 0
	for i in range(len(a)):
		num = '{:032b}'.format(a[i])
		for j in range(len(num)):
			if num[j] == '1':
				freq[j] += 1
	lis = []
	for i in range(32):
		if freq[i] > 0:
			lis.append(1)
		else:
			lis.append(0)
	s = ''.join((str(e) for e in lis))
	print(int(s, 2))
	for i in range(q):
		(x, v) = [int(x) for x in input().split()]
		tmp = a[x - 1]
		num = '{:032b}'.format(tmp)
		for j in range(len(num)):
			if num[j] == '1':
				freq[j] -= 1
		a[x - 1] = v
		num = '{:032b}'.format(v)
		for j in range(len(num)):
			if num[j] == '1':
				freq[j] += 1
		lis = []
		for i in range(32):
			if freq[i] > 0:
				lis.append(1)
			else:
				lis.append(0)
		s = ''.join((str(e) for e in lis))
		print(int(s, 2))


def findbin(n, cnt=31):
	ans = []
	res = 0
	while n > 0:
		res += 1
		val = n % 2
		ans.append(str(val))
		n //= 2
	while res < cnt:
		ans.append(str(0))
		res += 1
	ans.reverse()
	return ''.join(ans)
t = int(input())
for i in range(t):
	(n, q) = map(int, input().split())
	A = list(map(int, input().split()))
	w = []
	for j in range(q):
		(x, v) = map(int, input().split())
		w.append([x, v])
	res = 31
	bitl = [0] * res
	real_bit = ['0'] * res
	for j in range(len(A)):
		ans = findbin(A[j], res)
		for k in range(res):
			if ans[k] == '1':
				bitl[k] += 1
				real_bit[k] = '1'
	print(int(''.join(real_bit), 2))
	for j in range(q):
		val1 = findbin(A[w[j][0] - 1])
		val2 = findbin(w[j][1])
		A[w[j][0] - 1] = w[j][1]
		for k in range(res):
			if val1[k] != val2[k]:
				if val2[k] == '1':
					bitl[k] += 1
					real_bit[k] = '1'
				else:
					bitl[k] -= 1
					if bitl[k] == 0:
						real_bit[k] = '0'
		print(int(''.join(real_bit), 2))


def printbin(bitv, maxSize):
	sum = 0
	for i in range(maxSize):
		if bitv[i] > 0:
			sum = sum + pow(2, i)
	print(sum)
T = int(input())
while T:
	(N, Q) = map(int, input().split())
	A = list(map(int, input().split()))
	maxSize = 0
	bitv = [0] * 32
	for el in A:
		i = 0
		while el:
			if el % 2 != 0:
				bitv[i] += 1
			el = el // 2
			i += 1
		if i > maxSize:
			maxSize = i
	printbin(bitv, maxSize)
	for _ in range(Q):
		(X, V) = map(int, input().split())
		P = A[X - 1]
		A[X - 1] = V
		i = 0
		while P or V:
			if P % 2 != 0 and V % 2 == 0:
				bitv[i] -= 1
			elif P % 2 == 0 and V % 2 != 0:
				bitv[i] += 1
			P = P // 2
			V = V // 2
			i += 1
		if i > maxSize:
			maxSize = i
		printbin(bitv, maxSize)
	T -= 1


t = int(input())
for t1 in range(t):
	(n, q) = map(int, input().split())
	arr = list(map(int, input().split()))
	bits = [0 for i in range(32)]
	for i in arr:
		j = 0
		while i:
			if i % 2 == 1:
				bits[j] += 1
			j += 1
			i >>= 1
	ans = 0
	for i in range(32):
		if bits[i]:
			ans += 2 ** i
	print(ans)
	for q1 in range(q):
		(ind, n2) = map(int, input().split())
		n1 = arr[ind - 1]
		j = 0
		while n1:
			if n1 % 2 == 1:
				bits[j] -= 1
			j += 1
			n1 >>= 1
		arr[ind - 1] = n2
		j = 0
		while n2:
			if n2 % 2 == 1:
				bits[j] += 1
			j += 1
			n2 >>= 1
		ans = 0
		for i in range(32):
			if bits[i]:
				ans += 2 ** i
		print(ans)


t = int(input())
import math
for i in range(t):
	(n, q) = map(int, input().split())
	l = list(map(int, input().split()))
	ans = 0
	d = {}
	for k in range(32):
		d[k] = 0
		for z in range(n):
			if l[z] >> k & 1 == 1:
				d[k] = d[k] + 1
	for pp in range(32):
		if d[pp] > 0:
			ans = ans | 1 << pp
	print(ans)
	for j in range(q):
		ans = 0
		(x, v) = map(int, input().split())
		for pp in range(32):
			if 1 & l[x - 1] >> pp == 1:
				d[pp] = d[pp] - 1
			if 1 & v >> pp == 1:
				d[pp] = d[pp] + 1
		for pp in range(32):
			if d[pp] > 0:
				ans = ans | 1 << pp
		print(ans)
		l[x - 1] = v


t = int(input())
for _ in range(t):
	(n, q) = map(int, input().split())
	array = list(map(int, input().split()))
	freq = [0] * 31
	for i in array:
		j = 0
		while i > 0:
			rem = i % 2
			i //= 2
			freq[j] += rem
			j += 1
	ans = 0
	for i in range(31):
		if freq[i] > 0:
			ans += 2 ** i
	print(ans)
	for _ in range(q):
		(x, v) = map(int, input().split())
		prev = array[x - 1]
		array[x - 1] = v
		fin = 0
		j = 0
		while prev > 0:
			rem = prev % 2
			prev //= 2
			freq[j] -= rem
			j += 1
		j = 0
		while v > 0:
			rem2 = v % 2
			v //= 2
			freq[j] += rem2
			j += 1
		for j in range(31):
			if freq[j] > 0:
				fin += 2 ** j
		print(fin)


def gAns(li):
	dt = dict()
	n = len(li)
	ans = 0
	mul = 1
	for i in range(32):
		check = False
		dt[i] = 0
		for j in range(n):
			if li[j] & 1 << i > 0:
				dt[i] += 1
				check = True
		if check:
			ans = ans + mul
		mul *= 2
	return (ans, dt)

def gAAns(dt, pval, nval):
	for i in range(32):
		if pval & 1 << i > 0:
			dt[i] -= 1
		if nval & 1 << i > 0:
			dt[i] += 1
	ans = 0
	mul = 1
	for i in range(32):
		if dt[i]:
			ans += mul
		mul *= 2
	return (ans, dt)

def solve():
	(n, q) = map(int, input().split())
	li = list(map(int, input().split()))
	queries = [tuple(map(int, input().split())) for i in range(q)]
	(ans, dt) = gAns(li)
	print(ans)
	for (x, v) in queries:
		(ans, dt) = gAAns(dt, li[x - 1], v)
		li[x - 1] = v
		print(ans)
for tC in range(int(input())):
	solve()


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	a = [0] * 31
	k = 0
	for i in range(n):
		k |= l[i]
		s = bin(l[i]).replace('0b', '')
		for i in range(len(s)):
			a[30 - i] += int(s[len(s) - i - 1])
	print(k)
	for i in range(m):
		(c, d) = list(map(int, input().split()))
		s = bin(l[c - 1]).replace('0b', '')
		s1 = bin(d).replace('0b', '')
		for i in range(len(s)):
			a[30 - i] -= int(s[len(s) - i - 1])
		st = list('0') * 31
		for i in range(len(s1)):
			a[30 - i] += int(s1[len(s1) - i - 1])
		for i in range(31):
			if a[30 - i] > 0:
				st[30 - i] = '1'
		print(int(''.join(st), 2))
		l[c - 1] = d