#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int>pi;
int main() {
  int t;
  cin>>t;
  while(t--)
  {
      
     int n;
     cin>>n;
     
     int q[n];priority_queue<int,vector<int>,greater<int>>pq;
     for(int i=0;i<n;i++)
     {
         cin>>q[i];
     }
     
     for(int i=1;i<=n;i++)
     {
         pq.push(i);
     }
     bool vis[n+1];memset(vis,false,sizeof(vis));
     int prema=-1;
     int sm[n];
     for(int i=0;i<n;i++)
     {
         if(q[i]>prema)
         {
             sm[i]=q[i];
             vis[q[i]]=true;prema=q[i];
         }
         else
         {
             while(pq.empty()==false && vis[pq.top()])
             {
                 pq.pop();
             }
             sm[i]=pq.top();vis[pq.top()]=true;pq.pop();
         }
     }
     
     memset(vis,false,sizeof(vis));prema=-1;int la[n];memset(la,0,sizeof(la));
     priority_queue<int>pv;
     
     for(int i=0;i<n;i++)
     { if(q[i]>prema)
         {
             la[i]=q[i];
             vis[q[i]]=true;
             for(int j=q[i]-1;j>max(prema,0);j--)
             {
                 if(vis[j]==false)
                 {
                     pv.push(j);
                 }
             }
             
             prema=q[i];
         }
         else
         {
             la[i]=pv.top();
             vis[pv.top()]=true;
             pv.pop();
         }
    
     }
     
    
     for(int i=0;i<n;i++)
     {
         cout<<sm[i]<<" ";
     }
     cout<<endl;
   for(int i=0;i<n;i++)
   {
       cout<<la[i]<<" ";
   }
   cout<<endl;

  }
}