#include <bits/stdc++.h>

using namespace std;

#define ff first
#define ss second
#define vt vector
#define pb push_back
#define ppb pop_back
#define all(a) a.begin(), a.end()
#define ent "\n"
#define sp ' '

using ll  = long long;
using db  = double;
using ldb = long double;
using pll = pair <ll, ll>;
using pii = pair <int, int>;

const ll  INF = 8e18;
const ll  inf = 1e9 + 7;
const int MOD = 998244353;
const int bln = 200;
const int M   = 1e2 + 7;
const int N   = 1e6 + 7;

/*-------------------------main-------------------------*/

void solve() {
    #define test
    string s; cin >> s;
    while(s.size() > 0 && s.back() == '0') s.pop_back();
    reverse(s.begin(), s.end());
    for(auto cur : s) {
        if(cur == '5') cout << '2';
        else if(cur == '2') cout << '5';
        else cout << cur;
    }
}

void precalc() {
}

signed main() {
//  freopen("guard.in", "r", stdin);
//  freopen("guard.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    precalc();
    int testcases;
    #ifdef tests
        cin >> testcases;
    #endif
    #ifdef test
        testcases = 1;
    #endif
    while (testcases--) {
        solve();
    }
    return 0;
}
