#include < iostream > #include < cmath > using namespace std; int main() { long double e; long data,c,d,f; cin>>data; while(data-- > 0) { cin>>c; if(c<4) { for(d=2,f=1;d<=c;d++) f*=d; cout<<f<<endl; continue; } for(d=2,e=0.0;d<=c;d++) e += log10l((long double)d); while(e>=2.0) e -= 1.0; e = powl(10.0,e); c = e; while(e-c>0.99) c+=1; cout<<c%10<<endl; } return 0;}