#include <stdio.h>
#include <string.h>
using namespace std;
int main (){
int T,len,t,tool;
int shu[2][11]={{48,49,50,51,52,53,54,55,56,57},{79,79,84,84,70,70,83,83,69,78}};
char c[10];
scanf ("%d",&T);
getchar();
while(T--){
gets(c);
len=strlen(c);
for (t=len-1;t>=0;t--){
for (tool=0;tool<=10;tool++){
if (shu[0][tool]==c[t])
printf("%c",shu[1][tool]);
}
}
printf("\n");
}
return 0;
}
#include <string.h>
using namespace std;
int main (){
int T,len,t,tool;
int shu[2][11]={{48,49,50,51,52,53,54,55,56,57},{79,79,84,84,70,70,83,83,69,78}};
char c[10];
scanf ("%d",&T);
getchar();
while(T--){
gets(c);
len=strlen(c);
for (t=len-1;t>=0;t--){
for (tool=0;tool<=10;tool++){
if (shu[0][tool]==c[t])
printf("%c",shu[1][tool]);
}
}
printf("\n");
}
return 0;
}