t=int(input())
for jvbffdbin in range(t):
g=[0,5,8,8,2,3,5,2,9,4,1,1,7,6,4,7]
a='0588235294117647' #每16一循環
x=int(input())
x=x%16 #看他到第幾項
aa=x//16*sum(g)+sum(g[0:x]) #取和
print(a[x-1],aa)