Teacher Sungjae wanted to hold a programming competition for his students where every participant need to be included into  team. The participants submitted their team names before the deadline. After the competition ran for half an hour, (It is assured that each registered team will submit absolutely once within half an hour) Sungjae mistakenly pressed a button that changed the order of the registered team names. Now in the submission list, order of the characters in the team's name doesn't matter. That means $abc$, $acb$, $bac$, $bca$, $cab$, $cba$ refers to the same team. The competition ran for two hours and then ended. Sungjae now counting each of the team's score and wants to print the registered team names and score. The scoreboard should be ordered based on scores in decreasing order and if two teams have same score, Sangjae would follow lexicographical order.
$N$.$B$. frequency of each character's in a registered team's name will not match with another team. 
That means two teams named $xoxo$ and $oxox$ is not possible. Because both of them have the same frequency of each of the characters (two 'o' and two 'x'). Similarly $abb$ and $bab$ is not possible (because both of them have one 'a' and two 'b').
It is ensured that only possible test cases will be given.

-----Input:-----Input:
- 
First line will contain $T$, number of testcases. Then the testcases follow. 
- 
The first line of each test case contains two integers , $N$ and $R$ - total number of submissions and the number of submissions within first half an hour. 
- 
Then $R$  lines follow: the i'th line contains a string $ti$, registered names of the teams and an integer $pi$, points they got on that submission.
- 
Then $N-R$  lines follow: the i-th line contains a string $ti$- the i-th team's name (in any order) in lowercase letter only and $pi$ -points they got on that submission.

-----Output:-----Output:
For each testcase,print the scoreboard.
That means print the teams name and their point according to their score in decreasing order and if some of them have same score,print the teams name in lexicographical order

-----Constraints-----Constraints
- $1 \leq T \leq 10$
- $1 \leq R \leq N \leq 1000$
- $1 \leq ti \leq 1000$
- $1 \leq pi \leq 10^6$
Sum of points ($pi$) of a team will not cross $10^9$.

-----Sample Input:-----Sample Input:
1
10 5
amigoes  1
bannermen 1
monarchy 4
outliers 5
iniciador 10
aegimos 2
iiiacdnor 1
eilorstu 1
gimosae 3
mnachroy 7

-----Sample Output:-----Sample Output:
iniciador 11
monarchy 11
amigoes 6
outliers 6
bannermen 1

-----Explanation:-----Explanation:

$It$ $is$ $assured$ $that$ $each$ $team$ $will$ $submit$ $once$ $within$ $first$ $half$ $an$ $hour$.That means -                                          

that kind of submissions isn't possible within first half an hour.
Dataset can be huge. Use faster I/O method.

Starter code:

Solutions:
# cook your dish here
for t in range(int(input())):
    n,k=map(int,input().split())
    a=[]
    sr=[]
    for i in range(k):
        x,y=input().split()
        y=int(y)
        a.append([10**10-y,x])
        sr.append(sorted(x))
    for i in range(n-k):
        x,y=input().split()
        y=int(y)
        x=sorted(x)
        for j in range(k):
            if x==sr[j]:
                a[j][0]-=y
                break
    a.sort()
    for i in a:
        print(i[1],abs(i[0]-10**10))

for _ in range(int(input())):
    n,r=map(int,input().split())
    s=[]
    d=dict()
    for i in range(r):
        a,b=map(str,input().split())
        s.append([int(b),a])
        a=list(a)
        a.sort()
        d[''.join(a)]=i
    for i in range(n-r):
        a,b=map(str,input().split())
        a=list(a)
        a.sort()
        s[d[''.join(a)]][0]+=int(b)
    s.sort(key=lambda x:x[1], reverse=True)
    s.sort(key=lambda x:x[0])
    for i in range(-1,-r-1,-1):
        print(s[i][1],s[i][0])

for _ in range(int(input())):
    n,r=map(int,input().split())
    s=[]
    d=dict()
    for i in range(r):
        a,b=map(str,input().split())
        s.append([int(b),a])
        a=list(a)
        a.sort()
        d[''.join(a)]=i
    for i in range(n-r):
        a,b=map(str,input().split())
        a=list(a)
        a.sort()
        s[d[''.join(a)]][0]+=int(b)
    s.sort(key=lambda x:x[1], reverse=True)
    s.sort(key=lambda x:x[0])
    for i in range(-1,-r-1,-1):
        print(s[i][1],s[i][0])

# cook your dish here
for _ in range(int(input())):
    n, r = map(int, input().split())
    reg_teams = [input().split() for _ in range(r)]
    after = [input().split() for _ in range(n - r)]
    check1 = [[''.join(sorted(list(s))), int(p), s] for s, p in reg_teams]
    check2 = {}
    for a in after:
        cur = "".join(sorted(list(a[0])))
        if cur in check2.keys():
            check2[cur] += int(a[1])
        else:
            check2[cur] = int(a[1])
    for c in check1:
        if c[0] in check2.keys():
            c[1] += check2[c[0]]

    check1.sort(key = lambda z: z[2])
    check1.sort(key = lambda z: z[1], reverse = True)
    for c in check1:
        print(c[2], c[1])