#include <bits/stdc++.h>
using namespace std;
int zzxj(int x){
int cnt = 0;
while (x != 0){
cnt += x % 10;
x /= 10;
}
if (cnt >= 10){
zzxj(cnt);
} else {
return cnt;
}
}
bool p(long long int n){
bool b = 1;
long long int sum = 0, shi = 1;
while (n != 0){
int k = n % 10;
n /= 10;
if (b == 1){
k *= 7;
sum += zzxj(k) * shi;
shi *= 10;
b = 0;
continue;
}
sum += k * shi;
shi *= 10;
b = 0;
}
if (sum % 8 == 0){
return true;
} else {
return false;
}
}
int main(){
int m;
cin >> m;
long long int xx;
for (int i = 1; i <= m; i++){
cin >> xx;
if (p(xx) == true){
cout << 'T' << endl;
} else {
cout << 'F' << endl;
}
}
return 0;
}