喜欢打表

res=[3,5,9,15,21,25,27]
t=int(input())
for _ in range(0,t):
    k=int(input())
    k-=1
    print(k//7*30+res[k%7])