#include <vector>
#include <math.h>
#include<algorithm>
#include <iostream>
#include<set>
#include <string>
#include <math.h>
#include <numeric>
#include<map>
#include<queue>

#define pll pair<ll,ll>
#define pii pair<int,int>
//define ll long long int
#define vi vector<int>
#define vll vector<long long int>
#define ve vector
#define fi first
#define se second
#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
#define pb push_back
#define len(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define endl  '\n'
#define M_PI 3.14159265358979323846
#define re return
const int INF = 2 * 1e9;
//const ll MOD = 1000000007;
using namespace std;

#include <cassert>

#define int long long

void solve() {
   int n;
   cin>>n;
   vi a(n);
   vi minp(n);
   vi maxp(n);
   vi was(n+1,0);

   rep(i,n) cin>>a[i];
   int used = 1;
   int last = -1;
   rep(i,n) {
       if (last != a[i]) {
           last = a[i];
           was[a[i]] = 1;
           minp[i] = a[i];
       }
       else {
           while (was[used]) used++;
           was[used] = 1;
           minp[i] = used;
       }
   }

    used = 0;
   last = -1;
   vi v(n+1,0);
    rep(i,n) {
        if (last != a[i]) {

            for(int j=last+1;j<a[i];++j)
            {
                v[++used]=j;
            }
            last = a[i];
            maxp[i] = last;
        }
        else {
            maxp[i] = v[used--];
        }
    }

    rep(i,n) cout<<minp[i]<< " ";
    cout<<endl;
    rep(i,n)  cout<<maxp[i]<< " ";
    cout<<endl;
    re;

}


signed main() {
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    re 0;
}