#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, i, m, x;
    cin >> n;
    vector<long long> v, a;
    for (i = 0; i < n; i++) {
      cin >> x;
      v.push_back(x);
    }
    for (i = 0; i < n; i++) {
      cin >> x;
      a.push_back(x);
    }
    sort(v.begin(), v.end());
    sort(a.begin(), a.end());
    for (i = 0; i < n; i++) {
      cout << v[i] << " ";
    }
    cout << endl;
    for (i = 0; i < n; i++) {
      cout << a[i] << " ";
    }
    cout << endl;
  }
}
