#include <bits/stdc++.h>
using namespace std;
bool check (long long n) {
long long t = n;
long long ans = 0;
long long s = 0;
while (t) {
s++;
t /= 10;
}
t = n;
while (s) {
if (s % 2) {
long long f = t % 10;
f *= 7;
while (f > 9) {
long long s1 = 0;
while (f) {
s1 += f % 10;
f /= 10;
}
f = s1;
}
ans += f;
}
else ans += t % 10;
t /= 10;
s--;
}
if (ans % 8) return false;
else return true;
}
int main() {
int t;
cin >> t;
while (t--) {
long long x;
cin >> x;
if (check (x)) cout << "T" << endl;
else cout << "F" << endl;
}
return 0;
}