s = int((input())) # testy

for i in range(s):
    w = input().split()
    pa = [el for el in w[1:] if int(i-1) % 2 == 0]
    niepa = [el for el in w[1:] if int(i-1) % 2 == 1]

    print(' '.join(pa + niepa))
    #print(' '.join(niepa))
