int main(int argc, char const* argv[])
{
int q[8] = {9,8,7,6,5,4,3,2};
int t;
while(~scanf("%d",&t)){
while(t--){
long long n;
scanf("%lld",&n);
int sum = 0;
int k = 1;
int test = 1;
int tmp = n;
if(n != 1){
for(int i = 0;i<8;i++){
while(n%q[i] == 0){
n = n/q[i];
sum = sum+q[i]*k;
test = test*q[i];
k = k*10;
}
}
if(test != tmp){
sum = -1;
}
}
else
sum = 1;
printf("%d\n",sum);
}
}
return 0;
}