fork download
  1. s = int((input())) # testy
  2.  
  3. for i in range(s):
  4. w = input().split()
  5. pa = [el for el in w[1:] if int(i) % 2 == 0]
  6. niepa = [el for el in w[1:] if int(i) % 2 == 1]
  7.  
  8. print(' '.join(pa + niepa))
  9. #print(' '.join(niepa))
  10.  
Success #stdin #stdout 0.02s 5864KB
stdin
2 
4 1 2 3 5
3 9 8 7 
stdout
1 2 3 5
9 8 7