N = int(input()) lst = [] for i in range(N): lst.append(list(input().split(' '))) ans = '' for i in lst: ans = (i[1] if i[0] == '1' else '') + ans + (i[1] if i[0] == '0' else '') print(ans)