#include using namespace std; int F[1<<17][9]; int power(int a,int b){return b?power(a*a%9,b/2)*(b%2?a:1)%9:1;} int c(int a,int b) { int ret=1; for(int j=0;j<9;j++) { ret=ret*power(j,F[a][j]-F[a-b][j]-F[b][j])%9; } return ret; } main() { for(int i=1;i<1<<17;i++) { for(int j=0;j<9;j++)F[i][j]=F[i-1][j]; int t=i; for(int j=2;j*j<=t;j++) { while(t%j==0) { F[i][j%9]++; t/=j; } } if(t>1)F[i][t%9]++; } int N; cin>>N; for(;N--;) { string s;cin>>s; int ret=0; bool flag=false; for(int i=0;i