#include <bits/stdc++.h>
using namespace std;
const long long int mxsize = 3e5 + 5;
const long long int linf = 1e9;
const long double inf = 10000000000.0;
const long long int mod = 1e9 + 9;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    unordered_set<int> st;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
      cin >> b[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for (int i = 0; i < n; i++) {
      cout << a[i] << " ";
    }
    cout << endl;
    for (int i = 0; i < n; i++) {
      cout << b[i] << " ";
    }
    cout << endl;
  }
}
