#include <cstdio>
#include <iostream>
using namespace std;

bool f0, f1; //f0表示均不能整除,f1表示均能整除

int main() {
    int t;
    long long n, x;
    cin>>t;
    while (t--) {
        f0=f1=true;
        cin>>n;
        x=n;
        while(x){
            if(x%10==0)             f0=false; //0的整除要单独定义
            else if(n%(x%10) == 0)  f0=false;
            else                    f1=false;
            x/=10;
        }
        if(f1)       printf("G\n");
        else if (f0) printf("S\n");
        else         printf("H\n");
    }
    return 0;
}