#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long int> v1, v2;
    for (long long int i = 0; i < n; ++i) {
      long long x;
      cin >> x;
      v1.push_back(x);
    }
    for (long long int i = 0; i < n; ++i) {
      long long x;
      cin >> x;
      v2.push_back(x);
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    for (long long int i = 0; i < n; ++i) {
      cout << v1[i] << " ";
    }
    cout << endl;
    for (long long int i = 0; i < n; ++i) {
      cout << v2[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
