list=[]
list1=[]
u=int(input())
for i in range(u):
    list.append(int(input()))
for i in list:
    a=i
    b=0
    num=a
    while a!=0:
        list1.append(a%10)
        a=a//10
        b+=1
    q=0
    for t in list1:
        q+=t**b
    if q==num:
        print("T")
    else:
        print("F")