#include<bits/stdc++.h>
using namespace std;
int he1(long long nb){
int all=0;
for(;nb;nb/=10)all+=nb%10;
return all;
}
int main() {
int nb;
cin >> nb;
for (int i = 1; i <= nb; i++){
string n;
cin>>n;
int ge=n.size(),he=0;
for(int j=ge;j>=1;j--){
int num=n[j-1]-'0';
// cout<<num;
if(j%2!=0)
{
num*=7;
while(num>9){
num=he1(num);
}
he+=num;
cout<<he<<" ";
}
else he+=num;
}
// cout<<he<<endl;
if(he%8==0)cout<<"T"<<endl;
else cout<<"F"<<endl;
}
return 0;
}