#include<bits/stdc++.h>
using namespace std;
const int N = 50 + 5;
int a[N];
int f3(int s){
int x = s;
while(s > 9) {
s = 0;
while(x){
s += x % 10;
x /= 10;
}
if(s > 9) x = s;
}
return s;
}
int f2(int x){
if(x * 7 <= 9) return x * 7;
else {
f3(x * 7);
}
}
int f(int x){
int c = 0;
int a[25];
while(x){
c ++;
a[c] = x % 10;
x /= 10;
}
for(int i = 1; i <= c; i ++){
if(i % 2 == 1){
a[i] = f2(a[i]);
}
}
long long y = a[1];
for(int i = c; i >= 2; i --){
y = y * 10 + a[i];
}
}
bool pd(int x){
int s = 0;
while(x){
s += x % 10;
x /= 10;
}
if(s % 8 == 0) return 1;
else return 0;
}
int main(){
int n;
cin >> n;
for(int i = 1; i <= n; i ++){
cin >> a[i];
}
for(int i = 1; i <= n; i ++){
if(pd(f(a[i]))) cout << "T" << endl;
else cout << "F" << endl;
}
return 0;
}