#include <bits/stdc++.h>
using namespace std;
#define IOFast() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
int t, n, m, x, p1[200005], p2[200005];
queue<int> q;
stack<int> s;
int main()
{
    IOFast();
    cin >> t;
    while (t--)
    {
        m = 0;
        while (q.size())
            q.pop();
        while (s.size())
            s.pop();
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
            cin >> x;
            if (x > m)
            {
                p1[i] = x;
                p2[i] = x;
                for (int j = m + 1; j < x; j++)
                {
                    q.push(j);
                    s.push(j);
                }
                m = x;
                continue;
            }
            p1[i] = q.front();
            p2[i] = s.top();
            q.pop();
            s.pop();
        }
        for (int i = 1; i <= n; i++)
            cout << p1[i] << (i == n ? '\n' : ' ');
        for (int i = 1; i <= n; i++)
            cout << p2[i] << (i == n ? '\n' : ' ');
    }
    return 0;
}