Problem: A certain business maintains a list of all its customers' names. The list is arranged in order of importance, with the last customer in the list being the most important. Now, he want to create a new list sorted alphabetically according to customers' last names, but among customers with the same last name he want the more important ones to appear earlier in the new list. Alphabetical order (and equality of last names) should not be case sensitive.

Input:-
First line contains no. of test cases and first line of each test case contains n i.e. no. of elements and next n lines contains contains a name.

Output:- Print the new list with each element in a new line.

SAMPLE INPUT
2
5
Tom Jones
ADAMS
BOB ADAMS
Tom Jones
STEVE jONeS
3
Trudy
Trudy
TRUDY

SAMPLE OUTPUT
BOB ADAMS
ADAMS
STEVE jONeS
Tom Jones
Tom Jones
TRUDY
Trudy
Trudy

Solution (in PYTHON):

Solution:
def sorting(a, b):
    if a[-2].lower() == b[-2].lower():
        if a[-1] > b[-1]: return -1
        else: return 1
    elif a[-2].lower() < b[-2].lower():
        return -1
    return 1





def Print(a):
    for s in a[:-1]:
        print s,
    print

for  _ in xrange(input()):
    stack = []

    for i in xrange(input()):
        stack.append(raw_input().split()+[i])
    stack.sort(sorting)
    for s in stack:
        Print(s)