#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define  loop(n)     for(ll i=0;i<(n);i++)
#define  all(v)      v.begin(),v.end()
#define  pb          push_back
#define  ff          first
#define  ss          second
#define  sz(x)       (int)x.size()
 
const ll M=1e9+7;
const ll N1=1e5+10;
 
int code(){
    ll n;
    cin>>n;
    ll ar[n];
    loop(n) cin>>ar[i];
    set<ll> s1;
    set<ll,greater<ll>> s2;
    loop(n) s1.insert(i+1),s2.insert(i+1);
    vector<ll>  ans1(n),ans2(n);
    for(ll i=0;i<n;i++){
        if(s1.count(ar[i])){
            ans1[i]=ar[i];
            s1.erase(ar[i]);
        }
        else{
            ll tmp=*s1.begin();
            ans1[i]=tmp;
            s1.erase(tmp);
        }
        if(s2.count(ar[i])){
            ans2[i]=ar[i];
            s2.erase(ar[i]);
        }
        else{
            ll tmp=*s2.upper_bound(ar[i]);
            ans2[i]=tmp;
            s2.erase(tmp);
        }
    }
    for(auto x:ans1) cout<<x<<' ';
    cout<<"\n";
    for(auto x:ans2) cout<<x<<' ';
    cout<<"\n";
    return 0;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ll tc=1;
    cin>>tc;
    while(tc--)  code();
    return 0;
}