#include <iostream>
#include <cstring>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
int x;
string s;
while(cin>>x)
{
for(int i=1;i<=x;i++)
{
cin>>s;
int temp=0;
for(int j=0;j<s.size();j++)
{
if(s[j]>='0'&&s[j]<='9') temp++;
}
int check=0;
for(int j=0;j<s.size();j++)
{
if(s[j]>='0'&&s[j]<='9') check++;
if(check==temp)
{
check=j;
break;
}
}
int sum=0,mod,sol;
if(temp==10)
{
int a=10;
for(int k=0;k<check;k++)
{
if(s[k]>='0'&&s[k]<='9')
{
sum+=(s[k]-48)*a;
a--;
}
}
mod=sum%11;
sol=11-mod;
if(sol==11)
{
if(s[check]=='0') cout<<"T\n";
else cout<<"F\n";
}
else if(sol==10)
{
if(s[check]) cout<<"T\n";
else cout<<"F\n";
}
else
{
if(s[check]==sol+48) cout<<"T\n";
else cout<<"F\n";
}
}
else if(temp==13)
{
int a=1;
for(int k=0;k<check;k++)
{
if(s[k]>='0'&&s[k]<='9')
{
if(a%2==1)
{
sum+=s[k]-48;
}
else sum+=(s[k]-48)*3;
a++;
}
}
mod=sum%10;
sol=10-mod;
if(sol==10)
{
if(s[check]=='0') cout<<"T\n";
else cout<<"F\n";
}
else
{
if(s[check]==sol+48) cout<<"T\n";
else cout<<"F\n";
}
}
}
}
}