You are given $n$ of integers $a_1, a_2, \ldots, a_n$. Process $q$ queries of two types:

query of the form "0 $x_j$": add the value $x_j$ to all even elements of the array $a$,

query of the form "1 $x_j$": add the value $x_j$ to all odd elements of the array $a$.

Note that when processing the query, we look specifically at the odd/even value of $a_i$, not its index.

After processing each query, print the sum of the elements of the array $a$.

Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).


-----Input-----

The first line of the input contains an integer $t$ $(1 \leq t \leq 10^4$) — the number of test cases.

The descriptions of the test cases follow.

The first line of each test case contains two integers $n$ and $q$ ($1 \leq n$, $q \leq 10^5$) — the length of array $a$ and the number of queries.

The second line of each test case contains exactly $n$ integers: $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — elements of the array $a$.

The following $q$ lines contain queries as two integers $type_j$ and $x_j$ $(0 \leq type_j \leq 1$, $1 \leq x_j \leq 10^4$).

It is guaranteed that the sum of values $n$ over all test cases in a test does not exceed $10^5$. Similarly, the sum of values $q$ over all test cases does not exceed $10^5$.


-----Output-----

For each test case, print $q$ numbers: the sum of the elements of the array $a$ after processing a query.


-----Examples-----

Input
4
1 1
1
1 1
3 3
1 2 4
0 2
1 3
0 5
6 7
1 3 2 4 10 48
1 6
0 5
0 4
0 5
1 3
0 12
0 1
6 7
1000000000 1000000000 1000000000 11 15 17
0 17
1 10000
1 51
0 92
0 53
1 16
0 1
Output
2
11
14
29
80
100
100
100
118
190
196
3000000094
3000060094
3000060400
3000060952
3000061270
3000061366
3000061366


-----Note-----

In the first test case, the array $a = [2]$ after the first query.

In the third test case, the array $a$ is modified as follows: $[1, 3, 2, 4, 10, 48]$ $\rightarrow$ $[7, 9, 2, 4, 10, 48]$ $\rightarrow$ $[7, 9, 7, 9, 15, 53]$ $\rightarrow$ $[7, 9, 7, 9, 15, 53]$ $\rightarrow$ $[10, 12, 10, 12, 18, 56]$ $\rightarrow$ $[22, 24, 22, 24, 30, 68]$ $\rightarrow$ $[23, 25, 23, 25, 31, 69]$.

Difficulty: EASY
Tags: Mathematics

Implementation

Starter code:

Solutions:
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	e = 0
	o = 0
	for i in range(n):
		if a[i] % 2 == 0:
			e += 1
		else:
			o += 1
	ans = sum(a)
	for i in range(q):
		(p, v) = map(int, input().split())
		if p == 0:
			ans = ans + e * v
			if v % 2 == 1:
				e = 0
				o = n
		else:
			ans = ans + o * v
			if v % 2 == 1:
				e = n
				o = 0
		print(ans)


import sys
t = int(sys.stdin.readline().strip())
for i in range(t):
	nq = sys.stdin.readline().strip().split()
	n = int(nq[0])
	q = int(nq[1])
	array_line = sys.stdin.readline().strip().split()
	sum_a = 0
	count_odd = 0
	count_even = 0
	for e in array_line:
		en = int(e)
		sum_a += en
		if en % 2 == 0:
			count_even += 1
		else:
			count_odd += 1
	for qn in range(q):
		query = sys.stdin.readline().strip().split()
		x = int(query[1])
		if query[0] == '0':
			sum_a += count_even * x
			if x % 2 == 1:
				count_odd += count_even
				count_even = 0
		elif query[0] == '1':
			sum_a += count_odd * x
			if x % 2 == 1:
				count_even += count_odd
				count_odd = 0
		print(sum_a)


import sys
import math
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import heapq
sys.setrecursionlimit(200000)
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def cust():
	s = input()
	return s[:len(s) - 1]

def solve():
	(n, q) = inlt()
	arr = inlt()
	Sum = sum(arr)
	oddCount = 0
	evenCount = 0
	for i in arr:
		if i % 2 == 0:
			evenCount += 1
		else:
			oddCount += 1
	for _ in range(q):
		(b, x) = inlt()
		if b:
			Sum += oddCount * x
			if x % 2 == 1:
				evenCount += oddCount
				oddCount = 0
		else:
			Sum += evenCount * x
			if x % 2 == 1:
				oddCount += evenCount
				evenCount = 0
		print(Sum)
t = inp()
for _ in range(t):
	solve()


import sys
from pprint import pprint
input = sys.stdin.readline
T = int(input())
v = []
for i in range(T):
	(n, q) = map(int, input().split())
	L = [*map(int, input().split())]
	odd = 0
	even = 0
	for i in L:
		if i % 2 == 0:
			even += 1
		else:
			odd += 1
	sum_ = sum(L)
	for i in range(q):
		(operation, value) = map(int, input().split())
		if operation == 0:
			sum_ += even * value
			if value % 2 == 1:
				odd += even
				even = 0
		else:
			sum_ += odd * value
			if value % 2 == 1:
				even += odd
				odd = 0
		v.append(sum_)
print(*v, sep='\n')


import sys
from heapq import heapify, heappush, heappop
from math import ceil, floor, sqrt, gcd
from collections import defaultdict, deque
input = lambda : sys.stdin.readline().rstrip('\r\n')

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

def str_arr():
	return list(map(str, input().split()))

def get_str():
	return map(str, input().split())

def get_int():
	return map(int, input().split())

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

def solve():
	(n, q) = get_int()
	arr = int_arr()
	(o, e, tot) = (0, 0, 0)
	for i in arr:
		if i % 2 == 0:
			e += 1
		else:
			o += 1
		tot += i
	for i in range(q):
		(x, y) = get_int()
		if x == 0:
			tot += e * y
			if y % 2 == 1:
				o += e
				e = 0
			print(tot)
		elif x == 1:
			tot += o * y
			if y % 2 == 1:
				e += o
				o = 0
			print(tot)
T = 1
T = int(input())
while T:
	solve()
	T -= 1


import sys
input = sys.stdin.readline

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

def sol():
	N = readIntList()
	L = readIntList()
	(odd, ev) = (0, 0)
	for i in range(N[0]):
		if L[i] % 2 == 0:
			ev += 1
	odd = N[0] - ev
	s = sum(L)
	for _ in range(N[1]):
		A = readIntList()
		if A[0] == 1:
			s += odd * A[1]
			if A[1] % 2 == 1:
				ev += odd
				odd = 0
		if A[0] == 0:
			s += ev * A[1]
			if A[1] % 2 == 1:
				odd += ev
				ev = 0
		print(s)
t = int(input())
for _ in range(t):
	sol()


from sys import stdin, stdout
t = int(stdin.readline().strip())
for _ in range(t):
	(n, q) = map(int, stdin.readline().split())
	arr = list(map(int, stdin.readline().split()))
	summ = evens_count = odds_count = 0
	for num in arr:
		summ += num
		if num % 2 == 0:
			evens_count += 1
		else:
			odds_count += 1
	for _ in range(q):
		(typ, num) = map(int, stdin.readline().split())
		if typ == 0:
			summ += num * evens_count
			if num % 2 == 1:
				odds_count += evens_count
				evens_count = 0
		else:
			summ += num * odds_count
			if num % 2 == 1:
				evens_count += odds_count
				odds_count = 0
		print(summ)


import sys
t = int(sys.stdin.readline())
for test in range(t):
	(n, q) = map(int, sys.stdin.readline().split())
	a = list(map(int, sys.stdin.readline().split()))
	odd = 0
	even = 0
	for num in a:
		if num % 2 == 1:
			odd += 1
		else:
			even += 1
	ans = sum(a)
	for query in range(q):
		(key, x) = map(int, sys.stdin.readline().split())
		if key == 0:
			if x % 2 == 0:
				ans += even * x
			else:
				ans += even * x
				odd += even
				even = 0
		elif x % 2 == 0:
			ans += odd * x
		else:
			ans += odd * x
			even += odd
			odd = 0
		print(ans)


output = []
t = int(input())
for i in range(t):
	q = int(input().split(' ')[1])
	arr = [int(x) for x in input().split(' ')]
	tot = sum(arr)
	(o, e) = (0, 0)
	for x in arr:
		if x % 2 == 0:
			e += 1
		else:
			o += 1
	for j in range(q):
		(t, x) = [int(x) for x in input().split(' ')]
		if t == 0:
			tot += e * x
			if x % 2 == 1:
				o += e
				e = 0
		else:
			tot += o * x
			if x % 2 == 1:
				e += o
				o = 0
		output.append(str(tot))
print('\n'.join(output))


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	odd = sum((1 for i in range(n) if a[i] % 2 == 1))
	even = n - odd
	s = sum(a)
	for _ in range(q):
		(type, x) = map(int, input().split())
		if type == 0:
			s += even * x
			if x % 2 == 1:
				odd = n
				even = 0
		elif type == 1:
			s += odd * x
			if x % 2 == 1:
				even = n
				odd = 0
		print(s)


import sys
readline = sys.stdin.readline
T = int(readline())
for _ in range(T):
	(N, Q) = map(int, readline().split())
	A = list(map(int, readline().split()))
	SUM = sum(A)
	C = [0] * 2
	for a in A:
		C[a % 2] += 1
	add = 0
	for _ in range(Q):
		(cmd, x) = map(int, readline().split())
		if cmd == 0:
			add += C[0] * x
			if x % 2:
				C[1] += C[0]
				C[0] = 0
		else:
			add += C[1] * x
			if x % 2:
				C[0] += C[1]
				C[1] = 0
		print(SUM + add)


import sys, math
t = int(sys.stdin.readline())
for _ in range(t):
	even = 0
	odd = 0
	(n, q) = map(int, sys.stdin.readline().split())
	arr = list(map(int, sys.stdin.readline().split()))
	all_even = 0
	all_odd = 0
	num_even = 0
	num_odd = 0
	for i in arr:
		if i % 2 == 0:
			all_even += i
			num_even += 1
		else:
			all_odd += i
			num_odd += 1
	for i in range(q):
		(a, b) = map(int, sys.stdin.readline().split())
		if a == 0:
			all_even += b * num_even
			if b % 2 != 0:
				num_odd += num_even
				num_even = 0
		else:
			all_odd += b * num_odd
			if b % 2 != 0:
				num_even += num_odd
				num_odd = 0
		print(all_even + all_odd)


import sys
from collections import *
sys.setrecursionlimit(10 ** 5)
itr = (line for line in sys.stdin.read().strip().split('\n'))
INP = lambda : next(itr)

def ni():
	return int(INP())

def nl():
	return [int(_) for _ in INP().split()]
t = ni()
for case in range(t):
	(n, q) = nl()
	a = nl()
	(oddS, eveS) = (0, 0)
	tot = 0
	for i in a:
		tot += i
		if i % 2 == 0:
			eveS += 1
		else:
			oddS += 1
	for _ in range(q):
		(a, b) = nl()
		if a == 0:
			tot += b * eveS
			if b % 2 != 0:
				oddS += eveS
				eveS = 0
		else:
			tot += b * oddS
			if b % 2 != 0:
				eveS += oddS
				oddS = 0
		print(tot)


from sys import stdin
for i in range(int(stdin.readline().strip())):
	(x, y) = map(int, stdin.readline().strip().split())
	a2 = list(map(int, stdin.readline().strip().split()))
	v = sum(a2)
	ec = 0
	oc = 0
	for j in range(x):
		if a2[j] % 2 == 0:
			ec += 1
		else:
			oc += 1
	for j in range(y):
		(p, q) = map(int, stdin.readline().strip().split())
		if p == 1:
			v += q * oc
			if q % 2 != 0:
				ec += oc
				oc = 0
		elif p == 0:
			v += q * ec
			if q % 2 != 0:
				oc += ec
				ec = 0
		print(v)


import sys
input = sys.stdin.readline
for i in range(int(input())):
	(n, q) = map(int, input().split())
	l = list(map(int, input().split()))[:n]
	even_count = len(list(filter(lambda x: x % 2 == 0, l)))
	odd_count = len(list(filter(lambda x: x % 2 != 0, l)))
	s = sum(l)
	for _ in range(q):
		(t, x) = map(int, input().split())
		if t % 2 == 0:
			s += even_count * x
			if x % 2 != 0:
				odd_count += even_count
				even_count = 0
		else:
			s += odd_count * x
			if x % 2 != 0:
				even_count += odd_count
				odd_count = 0
		print(s)


import sys
input = sys.stdin.readline
for test in range(int(input())):
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	(e, o, es, os) = (0, 0, 0, 0)
	for i in a:
		if i % 2 == 0:
			es += i
			e += 1
		else:
			os += i
			o += 1
	for qu in range(q):
		(t, x) = map(int, input().split())
		if t == 0:
			if x % 2 == 0:
				es += e * x
			else:
				o += e
				es += e * x
				e = 0
				os += es
				es = 0
		elif x % 2 == 0:
			os += o * x
		else:
			e += o
			os += o * x
			o = 0
			es += os
			os = 0
		print(es + os)


def Incr(arr, qr):
	even = 0
	for x in arr:
		if x % 2 == 0:
			even += 1
	odd = len(arr) - even
	SUM = sum(arr)
	ans = []
	for q in qr:
		if q[0] == 0:
			SUM = SUM + even * q[1]
			if q[1] % 2 == 1:
				odd = len(arr)
				even = 0
		else:
			SUM = SUM + odd * q[1]
			if q[1] % 2 == 1:
				even = len(arr)
				odd = 0
		ans.append(SUM)
	return ans
OUTPUT = []
for _ in range(int(input())):
	(N, Q) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	qr = []
	for i in range(Q):
		qr.append([int(x) for x in input().split()])
	OUTPUT.extend(Incr(arr, qr))
for _ in OUTPUT:
	print(_)


from collections import Counter
import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	return str(input())

def invr():
	return map(int, input().split())
T = inp()
for i in range(T):
	arr = inlt()
	n = arr[0]
	q = arr[1]
	arr = inlt()
	ssum = sum(arr)
	o = 0
	e = 0
	for i in range(n):
		if arr[i] % 2 == 0:
			e += 1
		else:
			o += 1
	for i in range(q):
		x = inlt()
		if x[0] == 0:
			ssum += e * x[1]
			if x[1] % 2 != 0:
				o = o + e
				e = 0
		else:
			ssum += o * x[1]
			if x[1] % 2 != 0:
				e = o + e
				o = 0
		print(ssum)


import sys
count = int(sys.stdin.readline())
for _ in range(count):
	(n, q) = [int(f) for f in list(sys.stdin.readline().split())]
	a = [int(z) for z in list(sys.stdin.readline().split())]
	nc_arr = [x for x in a if x % 2 != 0]
	c_arr = [x for x in a if x % 2 == 0]
	nc_count = len(nc_arr)
	c_count = len(c_arr)
	nc_sum = sum(nc_arr)
	c_sum = sum(c_arr)
	for i in range(q):
		(command, adder) = [int(f) for f in list(sys.stdin.readline().split())]
		if command == 0:
			c_sum += c_count * adder
			if adder % 2 != 0:
				nc_count += c_count
				nc_sum += c_sum
				c_count = 0
				c_sum = 0
		if command == 1:
			nc_sum += nc_count * adder
			if adder % 2 != 0:
				c_count += nc_count
				c_sum += nc_sum
				nc_count = 0
				nc_sum = 0
		print(nc_sum + c_sum)


import collections
import sys
from typing import List
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, Counter, deque
from heapq import heappush, heappop
from itertools import accumulate
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
n = inp()
res = []
for _ in range(n):
	l = inlt()
	t = l[1]
	odd = []
	even = []
	for x in inlt():
		if x & 1:
			odd.append(x)
		else:
			even.append(x)
	odd_sum = sum(odd)
	odd_cnt = len(odd)
	even_sum = sum(even)
	even_cnt = len(even)
	for _ in range(t):
		(q, n) = inlt()
		if q == 0:
			even_sum += even_cnt * n
			if n & 1:
				odd_sum += even_sum
				odd_cnt += even_cnt
				even_sum = 0
				even_cnt = 0
		elif q == 1:
			odd_sum += odd_cnt * n
			if n & 1:
				even_sum += odd_sum
				even_cnt += odd_cnt
				odd_sum = 0
				odd_cnt = 0
		res.append(even_sum + odd_sum)
for x in res:
	print(x)


fl = 'input.txt'
import sys
import math
flh = sys.stdin
test_cases = int(flh.readline())
res = []
for case in range(test_cases):
	(n, q) = [int(x) for x in flh.readline().strip().split()]
	a = [int(x) for x in flh.readline().strip().split()]
	even_sum = 0
	odd_sum = 0
	even_count = 0
	odd_count = 0
	for i in a:
		if i % 2 == 0:
			even_count += 1
			even_sum += i
		else:
			odd_count += 1
			odd_sum += i
	for i in range(q):
		(t, num) = [int(x) for x in flh.readline().strip().split()]
		if t == 0:
			print(even_sum + odd_sum + num * even_count)
			if num % 2 == 0:
				even_sum += num * even_count
			else:
				odd_sum += num * even_count + even_sum
				odd_count += even_count
				even_count = 0
				even_sum = 0
		else:
			print(even_sum + odd_sum + num * odd_count)
			if num % 2 == 0:
				odd_sum += num * odd_count
			else:
				even_sum += num * odd_count + odd_sum
				even_count += odd_count
				odd_count = 0
				odd_sum = 0


from collections import defaultdict
t = int(input())
ans = list()
for _ in range(t):
	(m, n) = map(int, input().split())
	nums = list(map(int, input().split()))
	cnt = defaultdict(int)
	tmp = sum(nums)
	for num in nums:
		if num % 2 == 0:
			cnt[0] += 1
		else:
			cnt[1] += 1
	for i in range(n):
		(types, val) = map(int, input().split())
		if types == 0:
			tmp += cnt[0] * val
			if val % 2 != 0:
				cnt[1] += cnt[0]
				cnt[0] = 0
		else:
			tmp += cnt[1] * val
			if val % 2 != 0:
				cnt[0] += cnt[1]
				cnt[1] = 0
		ans.append(tmp)
for i in ans:
	print(i)


def naiveSolution(n, arr, q, qry):
	resutl = []
	for i in range(q):
		(qt, x) = qry[i]
		if qt == 0:
			for j in range(n):
				if arr[j] % 2 == 0:
					arr[j] += x
		else:
			for j in range(n):
				if arr[j] % 2 != 0:
					arr[j] += x
		resutl.append(sum(arr))
	return resutl

def solution(n, arr, q, qry):
	sm = 0
	even = 0
	odd = 0
	result = []
	for i in range(n):
		sm += arr[i]
		if arr[i] % 2 == 0:
			even += 1
		else:
			odd += 1
	for i in range(q):
		(x, y) = qry[i]
		if x == 0:
			sm += even * y
			if y % 2 != 0:
				odd += even
				even = 0
		else:
			sm += odd * y
			if y % 2 != 0:
				even += odd
				odd = 0
		result.append(sm)
	return result
result = []
t = int(input())
for i in range(t):
	(n, q) = [int(x) for x in input().split(' ')]
	arr = [int(x) for x in input().split(' ')]
	qry = []
	for j in range(q):
		qry.append([int(x) for x in input().split(' ')])
	result.append(solution(n, arr, q, qry))
for res in result:
	for s in res:
		print(s)


out = []
for _ in range(int(input())):
	(n, q) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	s = 0
	(even, odd) = (0, 0)
	for i in a:
		if i % 2 == 0:
			even += 1
		else:
			odd += 1
		s += i
	for __ in range(q):
		(t, x) = [int(i) for i in input().split()]
		if t == 0:
			s += even * x
			if x % 2 == 1:
				(even, odd) = (0, n)
		else:
			s += odd * x
			if x % 2 == 1:
				(even, odd) = (n, 0)
		out.append(s)
for i in out:
	print(i)


t = int(input())
ans = []
for _ in range(t):
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	koln = 0
	kolc = 0
	s = 0
	for i in a:
		if i % 2 == 0:
			kolc += 1
		else:
			koln += 1
		s += i
	for _ in range(q):
		(t, x) = map(int, input().split())
		if t == 0:
			s += kolc * x
			if x % 2 == 1:
				koln += kolc
				kolc = 0
		if t == 1:
			s += koln * x
			if x % 2 == 1:
				kolc += koln
				koln = 0
		ans.append(s)
for i in ans:
	print(i)


tt = int(input())
results = []
while tt > 0:
	tt -= 1
	(n, q) = map(int, input().split())
	a = [int(x) for x in input().split()]
	sums = sum(a)
	odd = 0
	even = 0
	for i in range(len(a)):
		if a[i] % 2 == 0:
			even += 1
		else:
			odd += 1
	for i in range(q):
		(t, x) = map(int, input().split())
		if t == 0:
			sums += even * x
			if x % 2 == 1:
				odd += even
				even = 0
		else:
			sums += odd * x
			if x % 2 == 1:
				even += odd
				odd = 0
		results.append(sums)
for i in range(len(results)):
	print(results[i])


from collections import defaultdict
from sys import stdin, stdout
import string

def solution(N, A, q_type, xj, even, odd, curr_sum):
	if q_type == 0:
		curr_sum += even * xj
		if xj % 2 == 1:
			odd += even
			even = 0
	if q_type == 1:
		curr_sum += odd * xj
		if xj % 2 == 1:
			even += odd
			odd = 0
	print(curr_sum)
	return (A, even, odd, curr_sum)
test_cases = int(stdin.readline())
for it in range(test_cases):
	(N, q) = (int(x) for x in stdin.readline().split())
	A = [int(x) for x in stdin.readline().split()]
	even = len([i for i in range(len(A)) if A[i] % 2 == 0])
	odd = len([i for i in range(len(A)) if A[i] % 2 == 1])
	curr_sum = sum(A)
	for it in range(q):
		(q_type, xj) = (int(x) for x in stdin.readline().split())
		(A, even, odd, curr_sum) = solution(N, A, q_type, xj, even, odd, curr_sum)


t = int(input())
res = []
for i in range(t):
	query = []
	(n, q) = map(int, input().split(' '))
	nums = list(map(int, input().split(' ')))
	even = [j for j in range(n) if nums[j] % 2 == 0]
	odd = [j for j in range(n) if nums[j] % 2 != 0]
	l_even = len(even)
	l_odd = len(odd)
	s = sum(nums)
	for j in range(q):
		(a, b) = map(int, input().split(' '))
		if a == 0:
			s += b * l_even
			res.append(s)
			if b % 2 != 0:
				l_odd += l_even
				l_even = 0
		else:
			s += b * l_odd
			res.append(s)
			if b % 2 != 0:
				l_even += l_odd
				l_odd = 0
for i in range(len(res)):
	print(res[i])


def f(arr, queries):
	odd = 0
	even = 0
	s = 0
	for el in arr:
		if el % 2 == 0:
			even += 1
		else:
			odd += 1
		s += el
	for (qt, v) in queries:
		if qt == 0:
			s += v * even
			if v % 2 == 1:
				odd += even
				even = 0
		else:
			s += v * odd
			if v % 2 == 1:
				even += odd
				odd = 0
		print(s)
t = int(input())
for i in range(t):
	(n, q) = [int(el) for el in input().split(' ')]
	arr = [int(el) for el in input().split(' ')]
	queries = []
	for j in range(q):
		(qt, v) = [int(el) for el in input().split(' ')]
		queries.append((qt, v))
	f(arr, queries)


def foo(n, q, ls, qs):
	even = 0
	odd = 0
	s = sum(ls)
	ans = []
	for i in ls:
		if i % 2:
			odd += 1
		else:
			even += 1
	for (type, i) in qs:
		if type == 0:
			s += even * i
			if i % 2:
				(odd, even) = (odd + even, 0)
			else:
				(odd, even) = (odd, even)
		else:
			s += odd * i
			if i % 2:
				(odd, even) = (0, odd + even)
			else:
				(odd, even) = (odd, even)
		ans.append(s)
	return ans
t = int(input())
for _ in range(t):
	(n, q) = [int(i) for i in input().split()]
	ls = [int(i) for i in input().split()]
	qs = []
	for _ in range(q):
		qs.append([int(i) for i in input().split()])
	for s in foo(n, q, ls, qs):
		print(s)


import math
from collections import defaultdict

def solve():
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	qa = []
	for i in range(q):
		qa.append(list(map(int, input().split())))
	e = 0
	o = 0
	sumi = sum(a)
	for i in a:
		if i % 2 == 0:
			e += 1
		else:
			o += 1
	for j in qa:
		if j[0] == 0:
			if j[1] % 2 == 0:
				sumi += e * j[1]
			else:
				sumi += e * j[1]
				o += e
				e = 0
		elif j[1] % 2 == 0:
			sumi += o * j[1]
		else:
			sumi += o * j[1]
			e += o
			o = 0
		print(sumi)

def main():
	for _ in range(int(input())):
		solve()
main()


def solve():
	(n, q) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	query = []
	for i in range(q):
		query.append(input().split())
	su = sum(arr)
	e = o = 0
	for i in arr:
		if i % 2 == 0:
			e += 1
		else:
			o += 1
	for i in query:
		if int(i[0]) % 2 == 0 and int(i[1]) % 2 == 0:
			su = su + e * int(i[1])
			print(su)
		elif int(i[0]) % 2 != 0 and int(i[1]) % 2 != 0:
			su = su + o * int(i[1])
			print(su)
			e = o + e
			o = 0
		elif int(i[0]) % 2 != 0 and int(i[1]) % 2 == 0:
			su = su + o * int(i[1])
			print(su)
		else:
			su = su + e * int(i[1])
			print(su)
			o = o + e
			e = 0
t = int(input())
while t:
	solve()
	t -= 1


def solve(n, q, a, y):
	odd = len([x for x in a if x % 2 != 0])
	even = len([x for x in a if x % 2 == 0])
	total = sum(a)
	for i in y:
		if i[0] == '0':
			total += even * int(i.split()[-1])
			if int(i.split()[-1]) % 2 != 0:
				odd += even
				even = 0
		else:
			total += odd * int(i.split()[-1])
			if int(i.split()[-1]) % 2 != 0:
				even += odd
				odd = 0
		print(total)
t = int(input())
while t:
	n = [int(x) for x in list(input().split())]
	(n, q) = (n[0], n[1])
	a = [int(x) for x in list(input().split())]
	queries = []
	for i in range(q):
		temp = input()
		queries.append(temp)
	solve(n, q, a, queries)
	t -= 1


from typing import List, Tuple

def solve1(As: List[int], xs: List[Tuple[int, int]]) -> List[int]:
	sum_as: int = 0
	cant_even_as: int = 0
	cant_odd_as: int = 0
	for a in As:
		sum_as += a
		if a % 2 == 0:
			cant_even_as += 1
		else:
			cant_odd_as += 1
	ans: List[int] = []
	for (t, x) in xs:
		if t == 0:
			sum_as += cant_even_as * x
			if x % 2 != 0:
				cant_odd_as += cant_even_as
				cant_even_as = 0
		else:
			sum_as += cant_odd_as * x
			if x % 2 != 0:
				cant_even_as += cant_odd_as
				cant_odd_as = 0
		ans.append(sum_as)
	return ans

def parse1() -> Tuple[List[int], List[Tuple[int, int]]]:
	(n, q) = map(int, input().split())
	As: List[int] = list(map(int, input().split()))
	xs: List[Tuple[int, int]] = [tuple(map(int, input().split())) for _ in range(q)]
	return (As, xs)

def main():
	t: int = int(input())
	for _ in range(t):
		(As, xs) = parse1()
		ans: List[int] = solve1(As, xs)
		print(*ans, sep='\n')
main()


t = int(input())
result = []
for i in range(t):
	(n, q) = list(map(int, input().split(' ')))
	ai = list(map(int, input().split(' ')))
	(sum, nbp, nbi) = (0, 0, 0)
	for j in ai:
		if j % 2 == 0:
			nbp += 1
		else:
			nbi += 1
		sum += j
	for j in range(q):
		(type, xj) = list(map(int, input().split(' ')))
		if (type == 0) & (xj % 2 == 1):
			sum += nbp * xj
			nbi += nbp
			nbp = 0
		elif (type == 0) & (xj % 2 == 0):
			sum += nbp * xj
		elif (type == 1) & (xj % 2 == 1):
			sum += nbi * xj
			nbp += nbi
			nbi = 0
		else:
			sum += nbi * xj
		result.append(sum)
for i in result:
	print(i)


t = int(input())
res = []

def calc(A, n):
	odd = []
	even = []
	sum = 0
	for i in range(0, n):
		sum += A[i]
		if A[i] % 2 == 0:
			even.append(A[i])
		else:
			odd.append(A[i])
	return (odd, even, sum)
for i in range(t):
	(n, q) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	(odd, even, sum_A) = calc(A, n)
	(odd_l, even_l) = (len(odd), len(even))
	for i in range(q):
		(type, x) = list(map(int, input().split()))
		if type == 0:
			if x % 2 == 0:
				sum_A += x * even_l
			else:
				sum_A += x * even_l
				odd_l += even_l
				even_l = 0
		elif x % 2 == 0:
			sum_A += x * odd_l
		else:
			sum_A += x * odd_l
			even_l += odd_l
			odd_l = 0
		res.append(sum_A)
print(*res, sep='\n')


class Solution:

	def __init__(self):
		n = int(input())
		for _ in range(n):
			(_, q) = [int(x) for x in input().split()]
			numbers = [int(x) for x in input().split()]
			queries = []
			for _ in range(q):
				queries.append([int(x) for x in input().split()])
			for n in solution(numbers, queries):
				print(n)

def solution(numbers, queries):
	(even, odd) = (0, 0)
	num_sum = 0
	for n in numbers:
		if n % 2 == 0:
			even += 1
		else:
			odd += 1
		num_sum += n
	response = []
	for q in queries:
		if q[0] == 0:
			num_sum += even * q[1]
			if q[1] % 2 != 0:
				odd += even
				even = 0
		else:
			num_sum += odd * q[1]
			if q[1] % 2 != 0:
				even += odd
				odd = 0
		response.append(num_sum)
	return response
Solution()


t = int(input())

def solve(n, q, nums, queries):
	(even, odd, total) = (0, 0, 0)
	for num in nums:
		if num % 2 == 0:
			even += 1
		else:
			odd += 1
		total += num
	result = []
	for (pol, val) in queries:
		if pol == 0:
			total += val * even
			if val % 2 == 0:
				pass
			else:
				odd += even
				even = 0
		else:
			total += val * odd
			if val % 2 == 0:
				pass
			else:
				even += odd
				odd = 0
		result.append(total)
	return result
for i in range(t):
	(n, q) = list(map(int, input().split()))
	nums = list(map(int, input().split()))
	queries = []
	for j in range(q):
		queries.append(list(map(int, input().split())))
	lst = solve(n, q, nums, queries)
	for ans in lst:
		print(ans)


def funct(n, q, arr, queries):
	even = 0
	odd = 0
	s = sum(arr)
	for i in arr:
		if i % 2 == 0:
			even += 1
		else:
			odd += 1
	for i in queries:
		if i[0] == 0:
			if i[1] % 2 == 0:
				s += even * i[1]
			else:
				s += even * i[1]
				odd += even
				even = 0
		elif i[1] % 2 == 0:
			s += odd * i[1]
		else:
			s += odd * i[1]
			even += odd
			odd = 0
		print(s)
t = int(input())
for i in range(t):
	(n, q) = map(int, input().split())
	arr = [int(ele) for ele in input().split()]
	queries = []
	for i in range(q):
		(a, b) = map(int, input().split())
		queries.append([a, b])
	funct(n, q, arr, queries)


t = int(input())
for _ in range(t):
	(n, q) = [int(x) for x in input().split(' ')]
	seq = [int(x) for x in input().split(' ')]
	queries = []
	for _ in range(q):
		queries.append([int(x) for x in input().split(' ')])
	odds = 0
	evens = 0
	odd_len = 0
	even_len = 0
	for num in seq:
		if num % 2 == 0:
			evens += num
			even_len += 1
		else:
			odds += num
			odd_len += 1
	for (q, num) in queries:
		if q % 2 == 0:
			evens += num * even_len
			if num % 2 != 0:
				odds += evens
				odd_len += even_len
				evens = 0
				even_len = 0
		else:
			odds += num * odd_len
			if num % 2 != 0:
				evens += odds
				even_len += odd_len
				odds = 0
				odd_len = 0
		print(evens + odds)


def solution():
	(n, q) = (int(num) for num in input().split())
	a = [int(num) for num in input().split()]
	queries = []
	for i in range(q):
		queries.append([int(num) for num in input().split()])
	even = 0
	odd = 0
	s = 0
	for num in a:
		if num % 2 == 0:
			even += 1
		else:
			odd += 1
		s += num
	ans = []
	for (type, x) in queries:
		if type == 0:
			s += even * x
			ans.append(s)
			if x % 2 == 1:
				odd += even
				even = 0
		else:
			s += odd * x
			ans.append(s)
			if x % 2 == 1:
				even += odd
				odd = 0
	for num in ans:
		print(num)

def main():
	t = int(input())
	while t:
		solution()
		t -= 1
main()


def even_odd_increments(n, q, array, queries):
	(even, odd) = (0, 0)
	(seven, sodd) = (0, 0)
	for i in range(len(array)):
		if array[i] % 2 == 0:
			seven += array[i]
			even += 1
		else:
			sodd += array[i]
			odd += 1
	for query in queries:
		evenodd = query[0]
		value = query[1]
		sum_ele = 0
		if evenodd == 0:
			if value % 2 == 0:
				seven += value * even
			else:
				sodd += seven + value * even
				odd += even
				(seven, even) = (0, 0)
		elif evenodd == 1:
			if value % 2 == 0:
				sodd += value * odd
			else:
				seven += sodd + value * odd
				even += odd
				(sodd, odd) = (0, 0)
		print(seven + sodd)
t = int(input())
for i in range(t):
	(n, q) = input().split(' ')
	(n, q) = (int(n), int(q))
	array = input().split(' ')
	array = [int(val) for val in array]
	queries = []
	for i in range(q):
		query = input().split(' ')
		query = [int(val) for val in query]
		queries.append(query)
	even_odd_increments(n, q, array, queries)


t = int(input())
ans = []
for _ in range(t):
	(n, q) = tuple(map(int, input().split()))
	a = list(map(int, input().split()))
	an = [[0, 0], [0, 0]]
	for i in a:
		if i % 2 == 0:
			an[0][0] += 1
			an[0][1] += i
		else:
			an[1][0] += 1
			an[1][1] += i
	for i in range(q):
		(ty, x) = tuple(map(int, input().split()))
		an[ty][1] += an[ty][0] * x
		if ty == 0 and x % 2 == 1:
			an[1][0] += an[0][0]
			an[1][1] += an[0][1]
			an[0] = [0, 0]
		elif ty == 1 and x % 2 == 1:
			an[0][0] += an[1][0]
			an[0][1] += an[1][1]
			an[1] = [0, 0]
		ans.append(an[0][1] + an[1][1])
for i in ans:
	print(i)


k = int(input())
for l in range(k):
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	b = []
	temp = []
	for i in range(q):
		(ind, val) = map(int, input().split())
		temp = [ind, val]
		b.append(temp)
	en = 0
	od = 0
	for i in range(n):
		if a[i] % 2 == 0:
			en += 1
		else:
			od += 1
	ans = sum(a)
	for i in range(q):
		aa = b[i][0]
		bb = b[i][1]
		if aa == 0 and bb % 2 == 0:
			ans = ans + en * bb
		elif aa == 0:
			ans += en * bb
			od += en
			en = 0
		if aa == 1 and bb % 2 == 0:
			ans += bb * od
		elif aa == 1:
			ans += bb * od
			en += od
			od = 0
		print(ans)


t = int(input())
for i in range(t):
	inp = input().split()
	(n, q) = (int(inp[0]), int(inp[1]))
	ls = list(map(int, input().split()))
	a = []
	for i in range(q):
		a.append(list(map(int, input().split())))
	(ev, od) = (0, 0)
	sum1 = 0
	for i in ls:
		if i % 2 == 0:
			ev += 1
			sum1 += i
		else:
			od += 1
			sum1 += i
	for i in a:
		if i[0] == 0:
			if i[1] % 2 == 0:
				sum1 += ev * i[1]
				print(sum1)
			else:
				od = n
				sum1 += ev * i[1]
				ev = 0
				print(sum1)
		elif i[1] % 2 == 0:
			sum1 += od * i[1]
			print(sum1)
		else:
			ev = n
			sum1 += od * i[1]
			od = 0
			print(sum1)


t = int(input())
for i in range(t):
	(n, q) = map(int, input().split())
	arr = list(map(int, input().split()))
	l = []
	for h in range(q):
		a = list(map(int, input().split()))
		l.append(a)
	even = 0
	s = 0
	for x in arr:
		if x % 2 == 0:
			even += 1
		s += x
	odd = n - even
	for h in l:
		(e, o) = (0, 0)
		if h[1] % 2 == 0:
			e = 1
		else:
			o = 1
		if h[0] == 0:
			if e:
				s += h[1] * even
			else:
				s += h[1] * even
				even = 0
				odd = n
		elif e:
			s += h[1] * odd
		else:
			s += h[1] * odd
			odd = 0
			even = n
		print(s)


n = int(input())
for z in range(n):
	(l, t) = [int(x) for x in input().split()]
	lis = [int(x) for x in input().split()]
	ops = []
	for i in range(t):
		ops.append([int(x) for x in input().split(' ', 1)])
	o = 0
	e = 0
	ss = sum(lis)
	for i in lis:
		if i % 2 == 0:
			e += 1
		else:
			o += 1
	for i in range(t):
		if ops[i][0] == 0:
			if ops[i][1] % 2 == 0:
				ss += e * ops[i][1]
			else:
				ss += e * ops[i][1]
				o += e
				e = 0
		elif ops[i][1] % 2 == 0:
			ss += o * ops[i][1]
		else:
			ss += o * ops[i][1]
			e += o
			o = 0
		print(ss)


for i in range(int(input())):
	(n, q) = list(map(int, input().split()))
	nums = list(map(int, input().split()))
	que = []
	for j in range(q):
		que.append(list(map(int, input().split())))
	isum = sum(nums)
	e = 0
	o = 0
	for it in nums:
		if it % 2 == 0:
			e += 1
		else:
			o += 1
	for k in que:
		if k[0] == 0:
			isum += e * k[1]
			if k[1] % 2 != 0:
				o += e
				e = 0
		else:
			isum += o * k[1]
			if k[1] % 2 != 0:
				e += o
				o = 0
		print(isum)


listOfNums = []
odd = []
even = []
listOfCommand = []
n = int(input())
for i in range(n):
	(len_array, len_oper) = map(int, input().split())
	listOfNums.append(list(map(int, input().split())))
	b = []
	for k in range(len_oper):
		b.append(list(map(int, input().split())))
	listOfCommand.append(b)
for i in range(len(listOfNums)):
	even = 0
	odd = 0
	sumList = sum(listOfNums[i])
	for k in range(len(listOfNums[i])):
		if listOfNums[i][k] % 2 == 0:
			even += 1
		else:
			odd += 1
	for k in range(len(listOfCommand[i])):
		if listOfCommand[i][k][0] == 0:
			sumList += even * listOfCommand[i][k][1]
			if listOfCommand[i][k][1] % 2 == 1:
				odd += even
				even = 0
		else:
			sumList += odd * listOfCommand[i][k][1]
			if listOfCommand[i][k][1] % 2 == 1:
				even += odd
				odd = 0
		print(sumList)


def evenOdds(n, q, nums, queries):
	tsum = sum(nums)
	evens = odds = 0
	for el in nums:
		if el % 2 == 0:
			evens += 1
		else:
			odds += 1
	freq = [[0, evens], [1, odds]]
	res = []
	for (st, val) in queries:
		isOdd = True
		if val % 2 == 0:
			isOdd = False
		for k in range(2):
			(ost, ct) = freq[k]
			if ost == 0 and st == 0:
				tsum += ct * val
				if isOdd:
					freq[k][0] = 1
			elif ost == 1 and st == 1:
				tsum += ct * val
				if isOdd:
					freq[k][0] = 0
		res.append(tsum)
	return res
T = int(input())
for i in range(T):
	(n, q) = [int(i) for i in input().split()]
	nums = [int(i) for i in input().split()]
	queries = []
	for j in range(q):
		(typei, x) = [int(i) for i in input().split()]
		queries.append([typei, x])
	out = evenOdds(n, q, nums, queries)
	for j in out:
		print(j)


t = int(input())
for j in range(t):
	(n, q) = map(int, input().split(' '))
	na = list(map(int, input().split(' ')))
	qa = []
	for m in range(q):
		qa.append(list(map(int, input().split(' '))))
	s = sum(na)
	ch = 0
	nch = 0
	for i in na:
		if i % 2 == 0:
			ch = ch + 1
		else:
			nch = nch + 1
	for i in range(q):
		if qa[i][0] == 0:
			s = s + ch * qa[i][1]
			if qa[i][1] % 2 != 0:
				nch = nch + ch
				ch = 0
		if qa[i][0] == 1:
			s = s + nch * qa[i][1]
			if qa[i][1] % 2 != 0:
				ch = ch + nch
				nch = 0
		print(s)


for _ in range(int(input())):
	(n, nq) = map(int, input().split())
	a = list(map(int, input().split()))
	q = list()
	for i in range(nq):
		q.append(list(map(int, input().split())))
	(odd, even) = (0, 0)
	(sev, sod) = (0, 0)
	for i in a:
		if i % 2 == 0:
			even += 1
			sev += i
		else:
			odd += 1
			sod += i
	for i in q:
		if i[0] % 2 == 0:
			sev += i[1] * even
			if i[1] % 2 == 1:
				odd += even
				even = 0
		else:
			sod += i[1] * odd
			if i[1] % 2 == 1:
				even += odd
				odd = 0
		print(sev + sod)


for t in range(int(input())):
	(n, q) = map(int, input().split())
	a = [int(s) for s in input().split()]
	t_p = []
	x = []
	for i in range(q):
		(tp, x_) = map(int, input().split())
		t_p.append(tp)
		x.append(x_)
	b = [k % 2 for k in a]
	odd = b.count(1)
	even = b.count(0)
	summ = sum(a)
	for i in range(q):
		if t_p[i] == 0:
			summ += even * x[i]
			if x[i] % 2 == 1:
				even = 0
				odd = n
		else:
			summ += odd * x[i]
			if x[i] % 2 == 1:
				even = n
				odd = 0
		print(summ)


T = int(input())
while T:
	(n, q) = map(int, input().split())
	l = list(map(int, input().split()))
	queries = []
	for i in range(q):
		queries.append(list(map(int, input().split())))
	(even, odd, some) = (0, 0, 0)
	for ele in l:
		if ele % 2 == 0:
			even += 1
		else:
			odd += 1
		some += ele
	ans = []
	for u in queries:
		if u[0] == 0:
			some = some + even * u[1]
			ans.append(some)
			if u[1] % 2 != 0:
				odd = odd + even
				even = 0
		else:
			some = odd * u[1] + some
			ans.append(some)
			if u[1] % 2 != 0:
				even = even + odd
				odd = 0
	for a in ans:
		print(a)
	T -= 1


t = int(input())
for _ in range(t):
	(n, q) = list(map(int, input().split()))
	lis = list(map(int, input().split()))
	process = []
	for u in range(q):
		process.append(list(map(int, input().split())))
	total = sum(lis)
	neven = 0
	nodd = 0
	for m in lis:
		if m % 2 == 0:
			neven += 1
		else:
			nodd += 1
	for i in process:
		a = i[0]
		b = i[1]
		if a % 2 != 0 and b % 2 != 0:
			total += nodd * b
			neven = n
			nodd = 0
			print(total)
		elif a % 2 == 0 and b % 2 == 0:
			total += neven * b
			print(total)
		elif a % 2 == 0 and b % 2 != 0:
			total += neven * b
			nodd = n
			neven = 0
			print(total)
		elif a % 2 != 0 and b % 2 == 0:
			total += nodd * b
			print(total)


t = int(input())
for i in range(t):
	(n, q) = map(int, input().split())
	l = [int(j) for j in input().split()]
	quer = []
	for k in range(q):
		q1 = [int(x) for x in input().split()]
		quer.append(q1)
	e = 0
	o = 0
	summ = sum(l[0:])
	for j in l:
		if j % 2 == 0:
			e += 1
		else:
			o += 1
	for k in quer:
		if k[0] == 0 and k[1] % 2 != 0:
			o += e
			summ = summ + e * k[1]
			e = 0
		elif k[0] == 1 and k[1] % 2 != 0:
			e += o
			summ = summ + o * k[1]
			o = 0
		elif k[0] == 0:
			summ = summ + e * k[1]
		elif k[0] == 1:
			summ = summ + o * k[1]
		print(summ)


for _ in range(int(input())):
	(n, q) = map(int, input().split())
	L = list(map(int, input().split()))
	L3 = []
	for k in range(n):
		if L[k] % 2 == 0:
			L3.append(0)
		else:
			L3.append(1)
	even = L3.count(0)
	odd = L3.count(1)
	total = sum(L)
	L2 = []
	for i in range(q):
		L2.append(tuple(map(int, input().split())))
	for j in range(q):
		if L2[j][0] == 0:
			print(total + even * L2[j][1])
			total = total + even * L2[j][1]
			if L2[j][1] % 2 == 1:
				odd += even
				even -= even
		else:
			print(total + odd * L2[j][1])
			total = total + odd * L2[j][1]
			if L2[j][1] % 2 == 1:
				even += odd
				odd -= odd


t = eval(input())
for i in range(t):
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	k = []
	k1 = [0] * 2
	for i in range(len(a)):
		if a[i] % 2 == 0:
			k1[0] += 1
		else:
			k1[1] += 1
	for i in range(q):
		k.append(list(map(int, input().split())))
	sun = sum(a)
	for i in range(len(k)):
		if k[i][0] == 1:
			sun += k[i][1] * k1[1]
			if k[i][1] % 2 == 1:
				k1[0] += k1[1]
				k1[1] = 0
		else:
			sun += k[i][1] * k1[0]
			if k[i][1] % 2 == 1:
				k1[1] += k1[0]
				k1[0] = 0
		print(sun)


times = int(input())
for time in range(times):
	(len_list, q) = map(int, input().split(' '))
	try:
		list1 = input().split(' ')
		for i in range(len(list1)):
			list1[i] = int(list1[i])
	except:
		list1 = [int(input())]
	q_list = []
	for i in range(q):
		m = [0] * 2
		q_list.append(m)
	for i in range(q):
		(x, y) = map(int, input().split(' '))
		q_list[i][0] = x
		q_list[i][1] = y
	ji = 0
	ou = 0
	sum_list = sum(list1)
	for i in range(len(list1)):
		if list1[i] % 2 == 0:
			ou += 1
		else:
			ji += 1
	for i in range(q):
		if q_list[i][0] == 0:
			sum_list += ou * q_list[i][1]
			print(sum_list)
			if q_list[i][1] % 2 == 1:
				ji += ou
				ou = 0
			else:
				pass
		else:
			sum_list += ji * q_list[i][1]
			print(sum_list)
			if q_list[i][1] % 2 == 1:
				ou += ji
				ji = 0


def process(queries, array, k):
	suma = sum(array)
	for i in range(len(queries)):
		if queries[i][1] % 2 == 0:
			if queries[i][0] == 0:
				suma += queries[i][1] * k['even']
			else:
				suma += queries[i][1] * k['odd']
		if queries[i][1] % 2 != 0:
			if queries[i][0] == 0:
				suma += queries[i][1] * k['even']
				k['odd'] += k['even']
				k['even'] = 0
			else:
				suma += queries[i][1] * k['odd']
				k['even'] += k['odd']
				k['odd'] = 0
		print(suma)
numberoftimestheprogramruns = int(input())
while numberoftimestheprogramruns > 0:
	(n, q) = input().split()
	n = int(n)
	q = int(q)
	array = input().split()
	k = {'even': 0, 'odd': 0}
	for i in range(len(array)):
		array[i] = int(array[i])
		if array[i] % 2 == 0:
			k['even'] += 1
		else:
			k['odd'] += 1
	queries = []
	t = q
	while q != 0:
		query = input().split()
		for i in range(len(query)):
			query[i] = int(query[i])
		queries.append(query)
		q = q - 1
	q = t
	numberoftimestheprogramruns -= 1
	process(queries, array, k)


from collections import defaultdict
from os import path
import sys
from collections import defaultdict
from turtle import st

def int_inp():
	return int(input())

def mul_inp():
	return map(int, input().split())

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

def solution():
	(n, q) = mul_inp()
	a = arr_inp()
	q = [arr_inp() for i in range(q)]
	n_odd = 0
	n_even = 0
	for i in range(n):
		if a[i] % 2 == 0:
			n_even += 1
		else:
			n_odd += 1
	s = sum(a)
	for i in range(len(q)):
		if q[i][0] == 0:
			s += n_even * q[i][1]
			print(s)
		else:
			s += n_odd * q[i][1]
			print(s)
		if q[i][1] % 2 == 1 and q[i][0] == 1:
			n_even = n
			n_odd = 0
		if q[i][1] % 2 == 1 and q[i][0] == 0:
			n_odd = n
			n_even = 0
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(int(input())):
	solution()


t = int(input())
nq_sp = []
a = []
q = []
for i in range(t):
	n_q = input()
	n_q = n_q.split()
	nq_sp.append([int(x) for x in n_q])
	a_inp = input()
	a_inp = a_inp.split()
	a.append([int(x) for x in a_inp])
	q.append([])
	for j in range(int(n_q[1])):
		q_inp = input()
		q_inp = q_inp.split()
		q[i].append([int(x) for x in q_inp])
for i in range(t):
	n = nq_sp[i][0]
	qq = nq_sp[i][1]
	s = sum(a[i])
	chet = [x % 2 for x in a[i]]
	n_chet = chet.count(0)
	n_nechet = chet.count(1)
	for j in range(qq):
		f = q[i][j][0]
		k = q[i][j][1]
		if f == 0:
			s += n_chet * k
			if k % 2 == 1:
				n_nechet += n_chet
				n_chet = 0
		else:
			s += n_nechet * k
			if k % 2 == 1:
				n_chet += n_nechet
				n_nechet = 0
		print(s)


def solve():
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	ec = 0
	oc = 0
	sum = 0
	for i in a:
		sum += i
		if i % 2 == 0:
			ec += 1
		else:
			oc += 1
	for i in range(q):
		(t, x) = map(int, input().split())
		if t == 0:
			sum += ec * x
			if x % 2 != 0:
				ec = 0
				oc = n
		else:
			sum += oc * x
			if x % 2 != 0:
				ec = n
				oc = 0
		print(sum)
for t in range(0, int(input())):
	solve()


import sys
sys.setrecursionlimit(10 ** 7)
mod = 10 ** 9 + 7

def readInt():
	return int(input())

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

def readStringList():
	return list(input())

def readStringListWithSpace():
	return list(input().split())

def readString():
	return input()

def execute():
	t = readInt()
	for _ in range(t):
		(n, q) = readIntList()
		arr = readIntList()
		(odd, even) = (0, 0)
		res = sum(arr)
		for (i, c) in enumerate(arr):
			if c & 1:
				odd += 1
			else:
				even += 1
		for __ in range(q):
			(ty, x) = readString().split(' ')
			x = int(x)
			if ty == '1':
				res += odd * x
				if x & 1:
					even += odd
					odd = 0
			else:
				res += even * x
				if x & 1:
					odd += even
					even = 0
			print(res)
execute()


def solve():
	(n, q) = map(int, input().split())
	(*a,) = map(int, input().split())
	s = sum(a)
	even = odd = 0
	for i in a:
		if i % 2 == 0:
			even += 1
	odd = n - even
	for _ in range(q):
		(typ, x) = map(int, input().split())
		if typ == 0:
			s += x * even
			if x % 2 == 1:
				even = 0
				odd = n
		else:
			s += x * odd
			if x % 2 == 1:
				even = n
				odd = 0
		print(s)
for _ in ' ' * int(input()):
	solve()


def solve():
	a = input().split()
	n = int(a[0])
	q = int(a[1])
	array = input().split()
	a = 0
	while a < n:
		array[a] = int(array[a])
		a += 1
	even = 0
	odd = 0
	a = 0
	while a < n:
		if array[a] % 2 == 0:
			even += 1
		else:
			odd += 1
		a += 1
	sum_ = sum(array)
	while q > 0:
		a = input().split()
		type = int(a[0])
		add = int(a[1])
		if type == 0:
			sum_ += even * add
			print(sum_)
		else:
			sum_ += odd * add
			print(sum_)
		if add % 2 == 1 and type == 0:
			odd += even
			even = 0
		elif add % 2 == 1 and type == 1:
			even += odd
			odd = 0
		q -= 1
t = int(input())
while t > 0:
	solve()
	t -= 1


def solve():
	(n, q) = list(map(int, input().split(' ')))
	arr = list(map(int, input().split(' ')))
	odd_count = 0
	even_count = 0
	curr_sum = sum(arr)
	for val in arr:
		if val % 2:
			odd_count += 1
		else:
			even_count += 1
	for _ in range(q):
		(typ, val) = list(map(int, input().split(' ')))
		if typ:
			curr_sum += odd_count * val
			if val % 2:
				even_count += odd_count
				odd_count = 0
		else:
			curr_sum += even_count * val
			if val % 2:
				odd_count += even_count
				even_count = 0
		print(curr_sum)
	return curr_sum

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


def even_odd_increment():
	(lenght_of_array, no_of_queries) = map(int, input().split())
	elements_of_araay = list(map(int, input().split()))
	even_length = 0
	odd_length = 0
	for e in elements_of_araay:
		if e % 2 == 0:
			even_length += 1
		else:
			odd_length += 1
	count = 0
	sum_of_array = sum(elements_of_araay)
	for i in range(no_of_queries):
		(type, increment) = map(int, input().split())
		if type == 0:
			if increment % 2 == 0:
				x = even_length * increment
				count += x
			else:
				x = even_length * increment
				count += x
				odd_length += even_length
				even_length = 0
		elif increment % 2 == 0:
			x = odd_length * increment
			count += x
		else:
			x = odd_length * increment
			count += x
			even_length += odd_length
			odd_length = 0
		print(sum_of_array + count)

def main():
	test_cases = int(input())
	for i in range(test_cases):
		even_odd_increment()
main()


def even_odd_increment():
	t = int(input())
	for i in range(t):
		(len_arr, no_of_queries) = map(int, input().split())
		elements = list(map(int, input().split()))
		(even, odd) = (0, 0)
		for e in elements:
			if e % 2 == 0:
				even += 1
			else:
				odd += 1
		increment = 0
		sum_array = sum(elements)
		for j in range(no_of_queries):
			(tj, xj) = map(int, input().split())
			if tj == 0:
				if xj % 2 == 0:
					x = even * xj
					increment += x
				else:
					x = even * xj
					increment += x
					odd += even
					even = 0
			elif xj % 2 == 0:
				x = odd * xj
				increment += x
			else:
				x = odd * xj
				increment += x
				even += odd
				odd = 0
			print(sum_array + increment)
even_odd_increment()


def solve():
	I = input
	(n, q) = map(int, I().split())
	a = list(map(int, I().split()))
	odd = [i for i in a if i % 2]
	even = [i for i in a if i % 2 == 0]
	(cnt, cnt1) = (sum(even), sum(odd))
	o = len(odd)
	e = len(even)
	for _ in range(q):
		(q_type, x) = map(int, I().split())
		if q_type:
			if x % 2:
				cnt1 = x * o + cnt1
				o = 0
				e = n
			else:
				cnt1 = x * o + cnt1
		elif x % 2:
			cnt = x * e + cnt
			e = 0
			o = n
		else:
			cnt = x * e + cnt
		print(cnt + cnt1)
for _ in range(int(input())):
	solve()


def check(n, q):
	st = input().split()
	s1 = 0
	s0 = 0
	sm = 0
	for el in st:
		eln = int(el)
		if eln % 2:
			s1 += 1
		else:
			s0 += 1
		sm += eln
	for ii in range(q):
		(t, x) = map(int, input().split())
		if t == 0:
			sm += s0 * x
			if x % 2:
				s1 += s0
				s0 = 0
		else:
			sm += s1 * x
			if x % 2:
				s0 += s1
				s1 = 0
		print(sm)
for i in range(int(input())):
	(a, b) = map(int, input().split())
	check(a, b)


import sys
import threading
from functools import lru_cache
from collections import defaultdict, deque

def main():
	t = int(input())
	for _ in range(t):
		(n, q) = [int(i) for i in input().split()]
		a = [int(i) for i in input().split()]
		even_count = 0
		odd_count = 0
		cur_sum = 0
		for num in a:
			if num % 2 == 0:
				even_count += 1
			else:
				odd_count += 1
			cur_sum += num
		for i in range(q):
			(type, x) = [int(i) for i in input().split()]
			if type == 0:
				cur_sum += even_count * x
			else:
				cur_sum += odd_count * x
			is_odd = x % 2 != 0
			if is_odd:
				if type == 0:
					odd_count = n
					even_count = 0
				else:
					odd_count = 0
					even_count = n
			print(cur_sum)
sys.setrecursionlimit(1 << 30)
threading.stack_size(1 << 27)
main_thread = threading.Thread(target=main)
main_thread.start()
main_thread.join()


def main():
	t = int(input())
	for _ in range(t):
		(n, q) = map(int, input().split())
		l = [int(x) for x in input().split()]
		od = ev = oc = ec = 0
		for i in l:
			if i % 2 == 1:
				od += i
				oc += 1
			else:
				ev += i
				ec += 1
		ans = 0
		for i in range(q):
			(a, b) = map(int, input().split())
			ans = 0
			if a == 0:
				ev += ec * b
				if b % 2 == 1:
					oc += ec
					ec = 0
					od += ev
					ev = 0
				ans = ev + od
			else:
				od += oc * b
				if b % 2 != 0:
					ec += oc
					oc = 0
					ev += od
					od = 0
				ans = od + ev
			print(ans)
main()


def main():
	t = int(input())
	for i in range(t):
		(n, q) = map(int, input().split())
		a = list(map(int, input().split()))
		jishu = [i for i in a if i % 2 == 1]
		jslen = len(jishu)
		oushulen = n - jslen
		sums = sum(a)
		for i in range(q):
			(z, xi) = map(int, input().split())
			if z == 0:
				sums += oushulen * xi
				if xi & 1:
					jslen = n
					oushulen = 0
				print(sums)
			else:
				sums += jslen * xi
				if xi & 1:
					oushulen = n
					jslen = 0
				print(sums)
main()


def main():
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	chet = 0
	nchet = 0
	total = 0
	for i in range(n):
		total += a[i]
		if a[i] % 2 == 0:
			chet += 1
		else:
			nchet += 1
	for _ in range(q):
		(tp, x) = map(int, input().split())
		sm = 0
		if tp == 0:
			total += x * chet
			if x % 2 == 1:
				nchet += chet
				chet = 0
		if tp == 1:
			total += x * nchet
			if x % 2 == 1:
				chet += nchet
				nchet = 0
		print(total)
for _ in range(int(input())):
	main()


for _ in range(int(input())):
	(n, q) = map(int, input().split())
	arr = list(map(int, input().split()))
	odd = 0
	even = 0
	ans = 0
	for x in arr:
		if x % 2 == 1:
			odd += 1
		else:
			even += 1
		ans += x
	while q > 0:
		(t, x) = map(int, input().split())
		if t == 0:
			ans += even * x
			if x % 2 == 1:
				odd += even
				even = 0
		else:
			ans += odd * x
			if x % 2 == 1:
				even += odd
				odd = 0
		print(ans)
		q -= 1


def solve():
	even_sum = 0
	odd_sum = 0
	odd_count = 0
	even_count = 0
	(n, q) = map(int, input().split())
	l = list(map(int, input().split()))
	for i in range(n):
		if l[i] % 2 == 0:
			even_sum += l[i]
			even_count += 1
		else:
			odd_sum += l[i]
			odd_count += 1
	add_sum = 0
	for j in range(q):
		(t, x) = map(int, input().split())
		if t == 0:
			add_sum += even_count * x
			if x % 2 != 0:
				odd_count += even_count
				even_count = 0
		else:
			add_sum += odd_count * x
			if x % 2 != 0:
				even_count += odd_count
				odd_count = 0
		print(even_sum + odd_sum + add_sum)
for i in range(int(input())):
	solve()


def solve():
	(n, q) = map(int, input().split())
	l = list(map(int, input().split()))
	(s, e, o) = (0, 0, 0)
	for i in range(n):
		if l[i] % 2:
			o += 1
		else:
			e += 1
		s += l[i]
	for i in range(q):
		(type, val) = map(int, input().split())
		if type == 0:
			s += val * e
			if val % 2:
				o += e
				e = 0
		else:
			s += val * o
			if val % 2:
				e += o
				o = 0
		print(s)
t = int(input())
for i in range(t):
	solve()


from collections import defaultdict

def main():
	t = int(input())
	for _ in range(t):
		(n, q) = map(int, input().split())
		(*nums,) = map(int, input().split())
		total = sum(nums)
		added = 0
		odds = 0
		evens = 0
		for num in nums:
			if num % 2 == 0:
				evens += 1
			else:
				odds += 1
		for query in range(q):
			(op, val) = map(int, input().split())
			if op == 0:
				added += evens * val
				if val % 2 != 0:
					odds += evens
					evens = 0
			elif op == 1:
				added += odds * val
				if val % 2 != 0:
					evens += odds
					odds = 0
			total = total + added
			print(total)
			added = 0
main()


def main():
	t = int(input())
	for i in range(t):
		(n, q) = map(int, input().split())
		a = list(map(int, input().split()))
		olen = len([i for i in a if not i % 2])
		jlen = n - olen
		suma = sum(a)
		for i in range(q):
			(z, xi) = map(int, input().split())
			if z == 0:
				suma += xi * olen
				if xi & 1:
					olen = 0
					jlen = n
				print(suma)
			else:
				suma += xi * jlen
				if xi & 1:
					olen = n
					jlen = 0
				print(suma)
main()


for _ in range(int(input())):
	(n, q) = map(int, input().split())
	oc = 0
	tc = 0
	for x in map(int, input().split()):
		tc += x
		oc += x % 2
	ec = n - oc
	for __ in range(q):
		(t, x) = map(int, input().split())
		if t == 0 and ec > 0:
			tc += ec * x
			if x % 2:
				ec = 0
				oc = n
		elif t == 1 and oc > 0:
			tc += oc * x
			if x % 2:
				oc = 0
				ec = n
		print(tc)


for _ in range(int(input())):
	(n, q) = map(int, input().split())
	arr = list(map(int, input().split()))
	ans = sum(arr)
	odds = 0
	evens = 0
	for num in arr:
		if num % 2:
			odds += 1
		else:
			evens += 1
	for _ in range(q):
		(a, b) = map(int, input().split())
		if not a:
			ans += evens * b
			if b % 2:
				odds += evens
				evens = 0
		else:
			ans += odds * b
			if b % 2:
				evens += odds
				odds = 0
		print(ans)


def single_case():
	(n, q) = list(map(int, input().split()))
	t = list(map(int, input().split()))
	s = sum(t)
	odd = sum((1 for el in t if el & 1))
	p = [len(t) - odd, odd]
	for _ in range(q):
		(parity, value) = list(map(int, input().split()))
		s += p[parity] * value
		if value & 1:
			p[parity ^ 1] = len(t)
			p[parity] = 0
		print(s)
z = int(input())
for _ in range(z):
	single_case()


for _ in range(int(input())):
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	count_odd = 0
	count_even = 0
	for i in a:
		if i % 2 == 0:
			count_even += 1
		else:
			count_odd += 1
	ans = sum(a)
	for i in range(q):
		(x, y) = map(int, input().split())
		if x == 1:
			ans += count_odd * y
			if y % 2 != 0:
				count_odd = 0
				count_even = n
		else:
			ans += count_even * y
			if y % 2 != 0:
				count_even = 0
				count_odd = n
		print(ans)


def solve():
	(n, q) = map(int, input().split())
	A = list(map(int, input().split()))
	evenNumbers = 0
	oddNumbers = 0
	evenSum = 0
	oddSum = 0
	for i in range(n):
		if A[i] % 2:
			oddNumbers += 1
			oddSum += A[i]
		else:
			evenNumbers += 1
			evenSum += A[i]
	for query in range(q):
		(type, x) = map(int, input().split())
		if type == 0:
			evenSum += evenNumbers * x
			if x % 2:
				oddNumbers += evenNumbers
				oddSum += evenSum
				evenNumbers = 0
				evenSum = 0
		else:
			oddSum += oddNumbers * x
			if x % 2:
				evenNumbers += oddNumbers
				evenSum += oddSum
				oddNumbers = 0
				oddSum = 0
		print(oddSum + evenSum)
for _ in range(int(input())):
	solve()


from collections import defaultdict
t = int(input())

def solve():
	(n, q) = map(int, input().split())
	arr = list(map(int, input().split()))
	sum_even = 0
	sum_odd = 0
	count_even = 0
	count_odd = 0
	for i in range(n):
		if arr[i] % 2 == 0:
			sum_even += arr[i]
			count_even += 1
		else:
			sum_odd += arr[i]
			count_odd += 1
	while q:
		(type, x) = map(int, input().split())
		if type == 0:
			sum_even += count_even * x
			print(sum_even + sum_odd)
			if x % 2 != 0:
				count_even = 0
				count_odd = n
		else:
			sum_odd += count_odd * x
			print(sum_odd + sum_even)
			if x % 2 != 0:
				count_even = n
				count_odd = 0
		q -= 1
while t:
	solve()
	t -= 1


def main():
	t = int(input())
	for _ in range(t):
		(n, q) = map(int, input().split())
		li = [int(x) for x in input().split()]
		(ev, od, sm) = (0, 0, 0)
		for i in li:
			if i % 2 == 0:
				ev += 1
			else:
				od += 1
			sm += i
		for __ in range(q):
			(typ, amt) = map(int, input().split())
			if typ == 0:
				sm += ev * amt
				if amt % 2 != 0:
					od += ev
					ev = 0
			else:
				sm += od * amt
				if amt % 2 != 0:
					ev += od
					od = 0
			print(sm)
main()


def opr():
	s = input().split()
	n = int(s[0])
	q = int(s[1])
	s = input().split()
	(odd, even, ans) = (0, 0, 0)
	for i in s:
		if int(i) % 2 == 0:
			even += 1
		else:
			odd += 1
		ans += int(i)
	for i in range(q):
		qr = input().split()
		if qr[0] == '0':
			ans += even * int(qr[1])
			if int(qr[1]) % 2 != 0:
				odd += even
				even = 0
		else:
			ans += odd * int(qr[1])
			if int(qr[1]) % 2 != 0:
				even += odd
				odd = 0
		print(ans)
T = int(input())
while T > 0:
	T -= 1
	opr()


t = int(input())
for _ in range(t):
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = sum(a)
	e = 0
	o = 0
	for ele in a:
		if ele % 2 == 0:
			e += 1
		else:
			o += 1
	for _ in range(q):
		(typej, xj) = map(int, input().split())
		if typej == 0:
			ans += e * xj
			if xj % 2 != 0:
				o += e
				e = 0
			print(ans)
		else:
			ans += o * xj
			if xj % 2 != 0:
				e += o
				o = 0
			print(ans)


t = int(input())
for _ in range(t):
	(n, q) = map(int, input().split())
	a = [int(x) for x in input().split()]
	sm = sum(a)
	evn = 0
	odd = 0
	for i in a:
		if i % 2 == 0:
			evn += 1
		else:
			odd += 1
	for _ in range(q):
		(x, y) = map(int, input().split())
		if x == 1:
			sm += odd * y
			if y % 2 != 0:
				evn = n
				odd = 0
		else:
			sm += evn * y
			if y % 2 != 0:
				evn = 0
				odd = n
		print(sm)


for _ in range(int(input())):
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	cnt_even = 0
	for j in a:
		if j % 2 == 0:
			cnt_even += 1
	cnt_odd = n - cnt_even
	for i in range(q):
		(type, x) = map(int, input().split())
		if type == 0:
			s = s + cnt_even * x
			if x % 2 == 1:
				cnt_odd = n
				cnt_even = 0
		else:
			s = s + cnt_odd * x
			if x % 2 == 1:
				cnt_even = n
				cnt_odd = 0
		print(s)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	ev = 0
	sump = sum(a)
	for j in range(n):
		if a[j] % 2 == 0:
			ev += 1
	od = n - ev
	for i in range(m):
		(x, y) = map(int, input().split())
		if x == 0:
			sump += ev * y
			if y % 2 == 1:
				ev = 0
				od = n
		else:
			sump += od * y
			if y % 2 == 1:
				ev = n
				od = 0
		print(sump)