#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")
 
#include <bits/stdc++.h>
 
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ins insert
#define sz(x) (int)x.size()
#define dbg(x) cout << x << "\n";
 
const int N = 2e5 + 5;
const long long int mod = 1e9 + 7;
const long long int Mod = 998244353;
const long double Pi = acos(-1);
const long long int Inf = 4e18;
 
using namespace std;
 
void TestCase (){
        int n;
        cin >> n;
        vector <int> q(n), mi(n), ma(n);
        for(int i = 0; i<n; i++) cin >> q[i];
        mi[0] = ma[0] = q[0];
        // minimum
        set <int> st;
        for(int i = 1; i<=n; i++) st.ins(i);
        st.erase(q[0]);
        for(int i = 1; i<n; i++){
                if(q[i] == q[i - 1]){
                        mi[i] = *st.begin();
                        st.erase(st.begin());
                }
                else{
                        mi[i] = q[i];
                        st.erase(q[i]);
                }
        }
        // maximum
        for(int i = 1; i<=n; i++) st.ins(i);
        st.erase(q[0]);
        int last = q[0];
        for(int i = 1; i<n; i++){
                if(q[i] == q[i - 1]){
                        auto low = st.lower_bound(last);
                        low--;
                        ma[i] = *low;
                        last = ma[i];
                        st.erase(low);
                }
                else{
                        ma[i] = q[i];
                        last = ma[i];
                        st.erase(ma[i]);
                }
        }
        for(int i = 0; i<n; i++) cout << mi[i] << " ";
        cout << "\n";
        for(int i = 0; i<n; i++) cout << ma[i] << " ";
}
 
int main(){
        IOS;
        int T = 1;
        cin >> T;
        while(T--){
                TestCase();
                cout << "\n";
        }
        return 0;
}