a=[0,5,8,8,2,3,5,2,9,4,1,1,7,6,4,7] b=[0,5,13,21,23,26,31,33,42,46,47,48,55,61,65,72] for _ in range(int(input())): c=int(input()) print(a[(c-1)%16],(c-1)//16*72+b[(c-1)%16])