#include <bits/stdc++.h>
#define X first
#define Y second
#define inf 10000000000000000
 
using namespace std;
 
const long long MAXN = 0;
const long long maxn = 0;
const long long mod = 1000000000+7;
 
long long t, n, m, k, temp, temp1, ok1, ok2, ans, res, sum;
 
int x[200000+9];
int used[200000+9], ok[200000+9];
set <int> s;
set <int>::iterator it;
 
 
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);     cout.tie(0);
 
    cin >> t;
    for(int u = 1; u <= t; u++){
        cin >> n;
        for (int i = 1; i <= n; i++){
            cin >> x[i];
            used[x[i]]++;
        }
 
        for (int i = 1; i <= n; i++){
            if (used[i] == 0)s.insert(i);
            else used[i] = 0;
        }
 
        it = s.begin();
        for (int i = 1; i <= n; i++){
            if(ok[x[i]] == 0){
                cout << x[i] << " ";
                ok[x[i]] = 1;
            }
            else{
                cout << *it << " ";
                it++;
            }
        }
        cout << '\n';
 
        for (int i = 1; i <= n; i++){
            if(ok[x[i]] == 1){
                cout << x[i] << " ";
                ok[x[i]] = 2;
            }
            else{
                it = s.lower_bound(x[i]);
                it--;
                cout << *it << " ";
                s.erase(it);
            }
        }
        cout << '\n';
 
        for (int i = 1; i <= n; i++)
            ok[i] = 0;
    }
}