#include <bits/stdc++.h>

using namespace std;

#define inf          1e15
#define mod          1000000007
#define N            100001
#define ll           long long int
#define vint         vector<int>
#define vll          vector<ll>
#define vstr         vector<string>
#define vvint        vector<vector<int> >
#define vvll         vector<vector<ll> >
#define vint_pair    vector<pair<int,int> >
#define input(arr)   for(auto &x:arr) cin>>x;
#define all(x)       (x).begin(), (x).end()
#define rall(x)      (x).rbegin(), (x).rend()

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        set<int>num;
        vint arr(n);
        for(int i=0;i<n;++i){
            cin>>arr[i];
            num.insert(arr[i]);
        }
        int vis[n+1];
        memset(vis, 0, sizeof(vis));
        int l = 1;
        for(int i=0;i<n;++i){
            if(vis[arr[i]]){
                cout<<l<<" ";
                vis[l] = 1;
            }
            else{
                cout<<arr[i]<<" ";
                vis[arr[i]] = 1;
            }
            while(vis[l]){
                ++l;
            }
        }
        cout<<'\n';
        set<int>st;
        memset(vis, 0, sizeof(vis));
        for(int i=1;i<=n;++i){
            if(num.find(i)==num.end()){
                st.insert(i);
            }
        }
        for(int i=0;i<n;++i){
            if(!vis[arr[i]]){
                cout<<arr[i]<<" ";
                vis[arr[i]] = 1;
            }
            else{
                auto it = st.lower_bound(arr[i]);
                --it;
                int tmp = *it;
                cout<<tmp<<" ";
                vis[tmp] = 1;
                st.erase(tmp);
            }
        }
        cout<<'\n';
    }
}
