#include <bits/stdc++.h>
using namespace std;
vector <int> ans;
int raz;
void perm(int tr, int N, vector<int> A, vector<int> v, set<int> poz)
{
    if (tr == N)
    {
        int razp = 0;
        /*for (int i = 0; i < N; i++)
        {
            if (razp < S/2) razp += A[v[i]];
        }*/
        if (razp < raz)
        {
            ans = v;
            raz = razp;
        }
        return;
    }
    for (int i = 0; i < N; i++)
    {
        if (poz.find(i) != poz.end()) continue;
        vector <int> vp = v;
        vp.push_back(i);
        set<int> pozp = poz;
        pozp.insert(i);
        perm(tr+1,N,A,vp,pozp);
    }
}
std::vector<int> solve(std::vector<int> A)
{
    ans.clear();
    int N = A.size();
    int i = 0, j = N-1, l = A[0], d = A[N-1];
    raz = l-d;
    while (i < j)
    {
        cout << i << " " << j << " " << l << " " << d << " " << raz << endl;
        if (l == d)
        {
            i++;
            d -= l;
            l = A[i];
            raz += l;
        }
        if (l > d)
        {
            j--;
            l -= d;
            d = A[j];
            raz -= d;
        }
        if (l < d)
        {
            i++;
            d -= l;
            l = A[i];
            raz += l;
        }
    }
    raz = abs(raz);
    cout << raz << endl;
    vector <int> vpoc;
    set<int> pozpoc;
    //perm(0,N,A,vpoc,pozpoc);
    return ans;
}
/*#include <bits/stdc++.h>
using namespace std;
vector <int> ans;
std::vector<int> solve(std::vector<int> A)
{
    ans.clear();
    int N = A.size(), ci;
    for (int i = 0; i < N; i++)
    {
        if (A[i] == (1<<(N-1))) ci = i;
    }
    ans.push_back(ci);
    for (int i = 0; i < N; i++)
    {
        if (i != ci) ans.push_back(i);
    }
    return ans;
}*/
/*#include <bits/stdc++.h>
using namespace std;
vector <int> ans, rep;
int br[300000007];
std::vector<int> solve(std::vector<int> A)
{
    ans.clear();
    rep.clear();
    for (int i = 0; i < A.size(); i++)
    {
        if (br[A[i]] % 2 == 0) ans.push_back(i);
        else rep.push_back(i);
        br[A[i]]++;
    }
    for (auto u : rep)
    {
        ans.push_back(u);
    }
    return ans;
}*/
/*vector <int> ans;
map <int,stack <int>> poz;
std::vector<int> solve(std::vector<int> A)
{
    for (int i = 0; i < A.size(); i++)
    {
        poz[A[i]].push(i);
    }
    sort(A.begin(), A.end());
    ans.clear();
    for (int i = 0; i < A.size(); i += 2)
    {
        ans.push_back(poz[A[i]].top());
        poz[A[i]].pop();
    }
    return ans;
}*/
vector <int> a;
int main()
{
    int n, t;
    cin >> t;
    while (t--)
    {
        cin >> n;
        a.clear();
        for (int i = 0; i < n; i++)
        {
            int b;
            cin >> b;
            a.push_back(b);
        }
        vector<int> aha = solve(a);
        for (auto u : aha)
        {
            cout << u << " ";
        }
        cout << endl;
        for (auto u : aha)
        {
            cout << a[u] << " ";
        }
        cout << endl;
    }
    return 0;
}
/*
8
1 1 2 1 3 3 2 1
*/
