#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,i;
        cin>>n;
        int arr[n];
        for(i=0;i<n;i++)
        cin>>arr[i];
        priority_queue<int> m1;
        priority_queue<int,vector<int>,greater<int>> m2;
        unordered_set<int> h1,h2;
        for(i=1;i<arr[0];i++){
            m1.push(i);
            m2.push(i);
        }
        vector<int> v1,v2;
        v1.push_back(arr[0]);
        v2.push_back(arr[0]);
        int max=arr[0];
        h1.insert(arr[0]);
        h2.insert(arr[0]);
        int j;
        for(i=1;i<n;i++){
            if(arr[i]>max && h1.find(arr[i])==h1.end()){
                v1.push_back(arr[i]);
                v2.push_back(arr[i]);
                h1.insert(arr[i]);
                h2.insert(arr[i]);
                for(j=max;j<arr[i];j++){
                if(h1.find(j)==h1.end())
                m1.push(j);
                if(h2.find(j)==h2.end())
                m2.push(j);
                }
                max=arr[i];
            }
            else{
                v1.push_back(m2.top());
                h2.insert(m2.top());
                m2.pop();
                v2.push_back(m1.top());
                h1.insert(m1.top());
                m1.pop();
            }
            
        }
        for(i=0;i<n;i++)
        cout<<v1[i]<<" ";
        cout<<endl;
        for(i=0;i<n;i++)
        cout<<v2[i]<<" ";
        cout<<endl;
    }
    return 0;
}