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: interview

Starter code:

Solutions:
# cook your dish here
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))


# cook your dish here
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 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))

  
  
 
 
  


# cook your dish here
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))
   
 
  
  
  
  
  
  


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


# cook your dish here
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)
 
 


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

# cook your dish here
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

# cook your dish here
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))



# cook your dish here
for _ in range(int(input())):
 n = int(input())
 d = {}
 for i in range(n):
  m,n = map(int,input().split())
  if m>=1 and m<=8:
   if m not in d:
    d[m]=n
   elif d[m]<n:
    d[m]=n
 print(sum(d.values())) 

# cook your dish here
for _ in range(int(input())):
 n=int(input())
 l=[]
 d=dict()
 for i in range(n):
  l=[int(i) for i in input().split()]
  if l[0] in [1,2,3,4,5,6,7,8]:
   if l[0] in list(d.keys()):
    if d[l[0]]<l[1]:
     d[l[0]]=l[1]
   else:
    d[l[0]]=l[1]
 s=0
 for i,j in list(d.items()):
  s=s+j
 print(s)


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 _ in range(int(input())):
 n = int(input())
 res = [0]*9
 for i in range(n):
  p, s = map(int, input().split())
  if 1 <= p <= 8:
   if res[p] < s:
    res[p] = s
 print(sum(res))

# cook your dish here
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
   else:
    if v > d[k] :
     d[k] = v
 if not d :
  print('0')
 else :
  x = d.values()
  x = list(x)
  print(sum(x))

# cook your dish here
for _ in range(int(input())):
 d={}
 n=int(input())
 for i in range(n):
  k,v=map(int,input().split())
  if(k<=8):
   if(k not in d.keys()):
    d[k]=v 
   else:
    if(d[k]<v):
     d[k]=v 
 print(sum(d.values()))

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)) 

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


# cook your dish here
rii = lambda : list(map(int, input().strip().split(" ")))
ril = lambda : list(map(int, input().strip().split(" ")))
ri = lambda : int(input().strip())
rs = lambda : eval(input())
T = ri()
for _ in range(T):
 N = ri()
 l = [0 for i in range(8)]
 for i in range(N):
  nb, S = rii()
  if nb < 9:
   l[nb-1] = max(S, l[nb-1])
 print(sum(l))


# cook your dish here
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))


# cook your dish here
for _ in range(int(input())):
 n=int(input())
 arr=[]
 for i in range(11):
  arr.append(0)
 for i in range(n):
  p,s=list(map(int,input().split()))
  if p<=8:
   arr[p-1]=max(arr[p-1],s)
 print(sum(arr))