You are participating in a contest which has $11$ problems (numbered $1$ through $11$). The first eight problems (i.e. problems $1, 2, \ldots, 8$) are scorable, while the last three problems ($9$, $10$ and $11$) are non-scorable ― this means that any submissions you make on any of these problems do not affect your total score.
Your total score is the sum of your best scores for all scorable problems. That is, for each scorable problem, you look at the scores of all submissions you made on that problem and take the maximum of these scores (or $0$ if you didn't make any submissions on that problem); the total score is the sum of the maximum scores you took.
You know the results of all submissions you made. Calculate your total score.

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains a single integer $N$ denoting the number of submissions you made.
- $N$ lines follow. For each $i$ ($1 \le i \le N$), the $i$-th of these lines contains two space-separated integers $p_i$ and $s_i$, denoting that your $i$-th submission was on problem $p_i$ and it received a score $s_i$.

-----Output-----
For each test case, print a single line containing one integer ― your total score.

-----Constraints-----
- $1 \le T \le 10$
- $1 \le N \le 1,000$
- $1 \le p_i \le 11$ for each valid $i$
- $0 \le s_i \le 100$ for each valid $i$

-----Subtasks-----
Subtask #1 (15 points): all submissions are on the same problem, i.e. $p_1 = p_2 = \ldots = p_N$
Subtask #2 (15 points): there is at most one submission made on each problem, i.e. $p_i \neq p_j$ for each valid $i, j$ ($i \neq j$)
Subtask #3 (70 points): original constraints

-----Example Input-----
2
5
2 45
9 100
8 0
2 15
8 90
1
11 1

-----Example Output-----
135
0

-----Explanation-----
Example case 1: The scorable problems with at least one submission are problems $2$ and $8$. For problem $2$, there are two submissions and the maximum score among them is $45$. For problem $8$, there are also two submissions and the maximum score is $90$. Hence, the total score is $45 + 90 = 135$.
Example case 2: No scorable problem is attempted, so the total score is $0$.

Difficulty: EASY

Solutions:
for i in range(int(input())):
	arr = [0] * 8
	for j in range(int(input())):
		(a, b) = map(int, input().split())
		if a in range(1, 9):
			arr[a - 1] = max(b, arr[a - 1])
	print(sum(arr))


for i in range(int(input())):
	result = dict()
	submissions = int(input())
	for j in range(submissions):
		(problem, score) = map(int, input().split(' '))
		if problem < 9:
			try:
				if result[problem] < score:
					result[problem] = score
			except:
				result[problem] = score
	total_marks = sum(result.values())
	print(total_marks)


for i in range(int(input())):
	n = int(input())
	d = {}
	for i in range(n):
		(a, b) = map(int, input().split())
		if a in d:
			d[a].append(b)
		else:
			d[a] = [b]
	c = 0
	for i in range(1, 9):
		if i in d:
			c += max(d[i])
	print(c)


n = int(input())
while n > 0:
	t = int(input())
	a = []
	for i in range(8):
		a.append(0)
	for i in range(t):
		(b, c) = [int(x) for x in input().split()]
		if b <= 8 and c > a[b - 1]:
			a[b - 1] = c
	print(sum(a))
	n = n - 1


for _ in range(int(input())):
	n = int(input())
	r = {}
	for i in range(1, 12):
		r[i] = 0
	for i in range(n):
		(p, s) = map(int, input().split())
		if r[p] < s:
			r[p] = s
		else:
			continue
	c = 0
	for i in range(1, 9):
		c += r[i]
	print(c)


a = int(input())
for i in range(a):
	b = int(input())
	e = {}
	for j in range(b):
		(c, d) = map(int, input().split())
		if c not in (9, 10, 11):
			if c not in e:
				e[c] = d
			elif e.get(c) < d:
				e[c] = d
	print(sum(e.values()))


for t in range(int(input())):
	n = int(input())
	l = [0] * 8
	for i in range(n):
		(p, s) = list(map(int, input().split()))
		if p <= 8 and l[p - 1] < s:
			l[p - 1] = s
	print(sum(l))


for _ in range(int(input())):
	n = int(input())
	a = []
	total = 0
	for i in range(n):
		(x, y) = map(int, input().split())
		a.append([x, y])
	a.sort()
	d = {i[0]: i[1] for i in a}
	for i in d.keys():
		if i <= 8:
			total += d[i]
	print(total)


for _ in range(int(input())):
	n = int(input())
	d = dict()
	c = 0
	l = []
	for i in range(n):
		(x, y) = map(int, input().split())
		l.append([y, x])
	l.sort()
	d = {i[1]: i[0] for i in l}
	for i in d.keys():
		if i <= 8:
			c += d[i]
	print(c)


for _ in range(int(input())):
	n = int(input())
	l = [0, 0, 0, 0, 0, 0, 0, 0, 0]
	for i in range(n):
		(s, p) = map(int, input().split())
		if s <= 8:
			if l[s - 1] < p:
				l[s - 1] = p
	print(sum(l))


t = int(input())
for i in range(t):
	n = int(input())
	A = [0] * 9
	for j in range(n):
		(a, b) = list(map(int, input().split()))
		if a < 9 and A[a] < b:
			A[a] = b
	print(sum(A))


for _ in range(int(input())):
	d = {}
	for i in range(1, 12):
		d[i] = 0
	for _ in range(int(input())):
		(n, p) = map(int, input().split())
		if d[n] < p:
			d[n] = p
		else:
			pass
	c = 0
	for i in range(1, 9):
		c += d[i]
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	a = [0]
	b = [0]
	c = [0]
	d = [0]
	e = [0]
	f = [0]
	g = [0]
	h = [0]
	for j in range(n):
		(q, s) = list(map(int, input().split()))
		if q < 9:
			if q == 1:
				a.append(s)
			elif q == 2:
				b.append(s)
			elif q == 3:
				c.append(s)
			elif q == 4:
				d.append(s)
			elif q == 5:
				e.append(s)
			elif q == 6:
				f.append(s)
			elif q == 7:
				g.append(s)
			elif q == 8:
				h.append(s)
	print(max(a) + max(b) + max(c) + max(d) + max(e) + max(f) + max(g) + max(h))


for _ in range(int(input())):
	n = int(input())
	fc = [0] * 9
	for i in range(n):
		(n, m) = map(int, input().split())
		if n < len(fc):
			if fc[n] < m:
				fc[n] = m
	print(sum(fc))


t = int(input())
for i in range(t):
	n = int(input())
	l = []
	c = 0
	for j in range(n):
		(x, y) = map(int, input().split())
		l.append([y, x])
	l.sort()
	d = {i[1]: i[0] for i in l}
	for k in d.keys():
		if k <= 8:
			c = c + d[k]
	print(c)


for _ in range(int(input())):
	n = int(input())
	d = {1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: []}
	l = []
	su = 0
	for i in range(n):
		(p, s) = list(map(int, input().split()))
		if p <= 8:
			d[p] = d[p] + [s]
	for j in d:
		if len(d[j]) != 0:
			su = su + max(d[j])
	print(su)


for _ in range(int(input())):
	a = int(input())
	b = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
	c = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
	for i in range(a):
		(d, e) = map(int, input().split())
		for j in range(len(b)):
			if d - 1 == j:
				if e > c[j]:
					c[j] = e
				break
	c[8] = c[9] = c[10] = 0
	print(sum(c))


for i in range(int(input())):
	d1 = {}
	n = int(input())
	for j in range(1, 12):
		d1[j] = 0
	for k in range(n):
		(p, s) = map(int, input().split())
		if d1[p] < s:
			d1[p] = s
		else:
			continue
	result = 0
	for l in range(1, 9):
		result += d1[l]
	print(result)


t = int(input())
for i in range(t):
	x = dict()
	a = int(input())
	for j in range(a):
		(p, s) = map(int, input().split())
		if p < 9:
			try:
				if x[p] < s:
					x[p] = s
			except:
				x[p] = s
	total = sum(x.values())
	print(total)


for _ in range(int(input())):
	Score = [0] * 8
	for _ in range(int(input())):
		(P, S) = list(map(int, input().split()))
		if P >= 1 and P <= 8:
			if Score[P - 1] < S:
				Score[P - 1] = S
	print(sum(Score))


T = int(input())
for i in range(T):
	n = int(input())
	l = [0] * 11
	for i in range(n):
		(X, Y) = map(int, input().split())
		if X < 9 and l[X - 1] < Y:
			l[X - 1] = Y
	print(sum(l))


for _ in range(int(input())):
	n = int(input())
	d = {}
	for i in range(n):
		(x, y) = map(int, input().split())
		if x <= 8:
			if x in d:
				y = max(d[x], y)
			d[x] = y
	a = 0
	for x in d.values():
		a += x
	print(a)


t = int(input())
for i in range(t):
	d = {}
	n = int(input())
	for j in range(n):
		(x, y) = map(int, input().split())
		if x in d:
			d[x].append(y)
		else:
			d[x] = [y]
	sum = 0
	prob = [1, 2, 3, 4, 5, 6, 7, 8]
	for j in d:
		if j in prob:
			sum += max(d[j])
	print(sum)


m = int(input())
for i in range(m):
	n = int(input())
	d = {}
	for i in range(n):
		(k, l) = list(map(int, input().split()))
		if k <= 8:
			if k in d:
				d[k] = max(l, d[k])
			else:
				d[k] = l
	print(sum(d.values()))


for _ in range(int(input())):
	n = int(input())
	hsh = [0] * 9
	for _ in range(n):
		(q, s) = map(int, input().split())
		if q in range(1, 9):
			if hsh[q] < s:
				hsh[q] = s
	print(sum(hsh))


for i in range(0, int(input())):
	n = int(input())
	l = []
	for j in range(n):
		l.append(list(map(int, input().split())))
	a = [0, 0, 0, 0, 0, 0, 0, 0]
	for k in range(0, len(l)):
		t = l[k][0]
		if t < 9:
			if l[k][1] >= a[t - 1]:
				a[t - 1] = l[k][1]
			else:
				continue
		else:
			continue
	print(sum(a))


p = int(input())
for z in range(p):
	n = int(input())
	a = []
	for i in range(8):
		a.append(0)
	for i in range(n):
		(x, y) = list(map(int, input().split()))
		if x <= 8 and y > a[x - 1]:
			a[x - 1] = y
	print(sum(a))


z = int(input())
for i in range(z):
	k = [0] * 8
	s = int(input())
	for j in range(s):
		(pos, sub) = map(int, input().split(' '))
		if pos < 9:
			if k[pos - 1] < sub:
				k[pos - 1] = sub
		else:
			continue
	print(sum(k))


n = int(input())
for i in range(n):
	d = {0: 0}
	s = 0
	x = int(input())
	for i in range(x):
		(p, q) = map(int, input().split())
		if p >= 1 and p <= 8:
			if p not in d:
				d[p] = q
			elif d[p] < q:
				d[p] = q
	for i in d.values():
		s += i
	print(s)


for _ in range(int(input())):
	n = int(input())
	maxs = dict()
	for i in range(1, n + 1):
		(p, s) = map(int, input().split())
		if p in maxs and p <= 8:
			maxs[p] = max(maxs[p], s)
		elif p <= 8:
			maxs[p] = s
	else:
		print(sum([v for (k, v) in maxs.items()]))


t = int(input())
for i in range(t):
	scores = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
	n = int(input())
	for i in range(n):
		(l, k) = [int(x) for x in input().split()]
		scores[l - 1] = max(scores[l - 1], k)
	sums = 0
	for i in range(8):
		sums += scores[i]
	print(sums)


T = int(input())
for i in range(0, T):
	scoredict = {}
	Sub = int(input())
	for j in range(0, Sub):
		(Q, Pt) = map(int, input().split())
		if Q <= 8:
			if Q not in scoredict or scoredict[Q] < Pt:
				scoredict[Q] = Pt
	print(sum(scoredict.values()))


t = int(input())
for i in range(t):
	n = int(input())
	x = [0] * 8
	for j in range(n):
		(a, b) = map(int, input().split())
		if a <= 8:
			x[a - 1] = max(x[a - 1], b)
	print(sum(x))


T = int(input())
for i in range(T):
	d = {}
	n = int(input())
	for j in range(n):
		(x, y) = map(int, input().split())
		if x not in d and x < 9:
			d[x] = y
		elif x in d and d[x] < y:
			d[x] = y
	print(sum(d.values()))


t = int(input())
for i in range(t):
	n = int(input())
	l = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
	for i in range(n):
		(p, s) = map(int, input().split())
		if s > l[p]:
			l[p] = s
	print(sum(l[0:9]))


t = int(input())
for z in range(t):
	n = int(input())
	d = {}
	for i in range(n):
		(k, v) = [int(x) for x in input().split()]
		if k < 9:
			if k not in d:
				d[k] = v
			elif v > d[k]:
				d[k] = v
	if not d:
		print('0')
	else:
		x = d.values()
		x = list(x)
		print(sum(x))


t = int(input())
for i in range(t):
	n = int(input())
	a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
	b = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
	for j in range(n):
		(p, q) = map(int, input().split())
		for k in range(len(b)):
			if k == p - 1:
				if q > b[k]:
					b[k] = q
	b[8] = b[9] = b[10] = 0
	print(sum(b))


for i in range(int(input())):
	n = int(input())
	d = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0}
	for i in range(n):
		(k, v) = map(int, input().split())
		if k < 9 and d[k] < v:
			d[k] = v
	l = d.values()
	print(sum(l))


for _ in range(int(input())):
	n = int(input())
	d = {}
	for i in range(n):
		(a, b) = map(int, input().split())
		if a <= 8:
			try:
				if d[a] < b:
					d[a] = b
			except:
				d[a] = b
	s = sum(d.values())
	print(s)


for _ in range(int(input())):
	n = int(input())
	s = [0] * 8
	for i in range(n):
		(p, m) = list(map(int, input().split()))
		if p < 9 and s[p - 1] < m:
			s[p - 1] = m
	print(sum(s))


t = int(input())
for i in range(t):
	n = int(input())
	l = [0] * 12
	for j in range(0, n):
		(x, y) = map(int, input().split())
		if y > l[x]:
			l[x] = y
	sum = 0
	for k in range(1, 9):
		sum = sum + l[k]
	print(sum)


for _ in range(int(input())):
	d = {}
	s = int(input())
	for j in range(1, 12):
		d[j] = 0
	for i in range(s):
		(k, n) = map(int, input().split())
		if d[k] < n:
			d[k] = n
		else:
			continue
	result = 0
	for i in range(1, 9):
		result += d[i]
	print(result)


t = int(input())
for i in range(t):
	n = int(input())
	d = {}
	for j in range(n):
		(q, s) = list(map(int, input().split()))
		if q <= 8:
			if q in d:
				d[q] = max(d[q], s)
			else:
				d[q] = s
	sum = 0
	for key in d:
		sum = sum + d[key]
	print(sum)


t = int(input())
for i in range(t):
	ls = []
	n = int(input())
	sumv = 0
	for j in range(8):
		ls.append(0)
	for k in range(n):
		(x, y) = map(int, input().split())
		if x - 1 < 8:
			if ls[x - 1] < y:
				ls[x - 1] = y
	for l in range(8):
		sumv += ls[l]
	print(sumv)


for _ in range(int(input())):
	n = int(input())
	scores = [0] * 8
	for _ in range(n):
		(p, s) = map(int, input().split())
		if p <= 8:
			scores[p - 1] = max(scores[p - 1], s)
	print(sum(scores))


for i in range(int(input())):
	result = {}
	for j in range(1, 12):
		result[j] = 0
	submissions = int(input())
	for j in range(submissions):
		(problem, score) = map(int, input().split(' '))
		if result[problem] < score:
			result[problem] = score
		else:
			continue
	total_marks = 0
	for j in range(1, 9):
		total_marks += result[j]
	print(total_marks)


for i in range(int(input())):
	n = int(input())
	l = []
	sum = 0
	for i in range(n):
		(pi, ai) = map(int, input().split())
		l.append([ai, pi])
	l.sort()
	d = {i[1]: i[0] for i in l}
	for i in d.keys():
		if i <= 8:
			sum = sum + d[i]
	print(sum)


for _ in range(int(input())):
	n = int(input())
	a = [0, 0, 0, 0, 0, 0, 0, 0]
	for i in range(n):
		(n, m) = list(map(int, input().split()))
		if n == 9 or n == 10 or n == 11:
			continue
		elif a[n - 1] < m:
			a[n - 1] = m
	print(sum(a))


n = int(input())
for i in range(n):
	m = int(input())
	l = [0] * 8
	for i in range(m):
		(a, b) = map(int, input().split())
		if a > 0 and a <= 8:
			if l[a - 1] < b:
				l[a - 1] = b
	print(sum(l))


for i in range(int(input())):
	l = [0 for i in range(11)]
	for i in range(int(input())):
		(p, s) = map(int, input().split())
		l[p - 1] = max(l[p - 1], s)
	print(sum(l[:8]))