int input pairs for in range capital state input split pairs append ca

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
n = int(input())
pairs = []
for i in range(n):
capital, state = input().split()
pairs.append((capital, state))
pairs.sort(key=lambda pair: pair[1])
print('\n'.join([f'{capital} {state}' for capital, state in pairs]))