#include<bits/stdc++.h>
#define ll long long;
using namespace std;
vector <long long> miniperm(vector<long long> v, long long n){
    set<long long> s;
    for(long long i=1; i<=n; i++){
        s.insert(i);
    }
    vector<long long> res;
    for(long long i=0; i<v.size(); i++){
        if(i==0 || v[i] != v[i-1]){
            res.push_back(v[i]);
            s.erase(v[i]);
        }
        else{
            auto pos = s.begin();
            res.push_back(*pos);
            s.erase(*pos);
        }
    }
    return res;
}

vector<long long> maxiperm(vector<long long> v, long long n){
    set<long long> s;
    for(long long i=-1; i>=-n; i--){
        s.insert(i);
    }
    
    vector<long long> res;
    for(long long i=0; i<v.size(); i++){
        if(i==0 || v[i] != v[i-1]){
            res.push_back(v[i]);
            s.erase(-v[i]);
        }
        else{
            res.push_back(-(*s.lower_bound(-v[i])));
            s.erase(s.lower_bound(-v[i]));
        }
    }
    return res;
}

int main(){
    long long t;
    cin>>t;
    while(t--){
        long long n;
        cin>>n;
        vector<long long> v;
        for(long long i=0; i<n; i++){
            long long le;
            cin>>le;
            v.push_back(le);
        }
        vector<long long> mini = miniperm(v, n);
        vector<long long> maxi = maxiperm(v, n);
        for(auto it: mini){
            cout<<it<<" ";
        }
        cout<<endl;
        for(auto it: maxi){
            cout<<it<<" ";
        }
        cout<<endl;
        
    }
}