#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int i=0; int n=0; cin>>n; for(i=0;i<n;i++) { string a; string ans; cin>>a; vector <int> z(26,0); int j=0; int len=a.size(); for(j=0;j<len;j++) { z[a[j]-'A']++; } if(z[25]) { for(j=0;j<z[25];j++) { ans+='2'; } z['O'-'A']-=z[25]; z['R'-'A']-=z[25]; } if(z['G'-'A']) { for(j=0;j<z['G'-'A'];j++) { ans+='0'; } z['I'-'A']-=z['G'-'A']; } if(z['X'-'A']) { for(j=0;j<z['X'-'A'];j++) { ans+='8'; } z['S'-'A']-=z['X'-'A']; z['I'-'A']-=z['X'-'A']; } if(z['W'-'A']) { for(j=0;j<z['W'-'A'];j++) { ans+='4'; } z['O'-'A']-=z['W'-'A']; } if(z['U'-'A']) { for(j=0;j<z['U'-'A'];j++) { ans+='6'; } z['R'-'A']-=z['U'-'A']; z['O'-'A']-=z['U'-'A']; } if(z['O'-'A']) { for(j=0;j<z['O'-'A'];j++) { ans+='3'; } } if(z['S'-'A']) { for(j=0;j<z['S'-'A'];j++) { ans+='9'; } z['V'-'A']-=z['S'-'A']; } if(z['V'-'A']) { for(j=0;j<z['V'-'A'];j++) { ans+='7'; } z['I'-'A']-=z['V'-'A']; } if(z['R'-'A']) { for(j=0;j<z['R'-'A'];j++) { ans+='5'; } } if(z['I'-'A']) { for(j=0;j<z['I'-'A'];j++) { ans+='1'; } } sort(ans.begin(),ans.end()); cout<<ans; if(i!=n-1) { cout<<endl; } } return 0; }