#include <bits/stdc++.h>
using namespace std;
long long n, m, i, t, ans, sum, mx, j, k, a, b;
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    vector<long long> v(n);
    vector<long long> vv(n);
    for (i = 0; i < n; i++) {
      cin >> v[i];
    }
    for (i = 0; i < n; i++) {
      cin >> vv[i];
    }
    sort(v.begin(), v.end());
    sort(vv.begin(), vv.end());
    for (i = 0; i < n; i++) {
      cout << v[i] << " ";
    }
    cout << "\n";
    for (i = 0; i < n; i++) {
      cout << vv[i] << " ";
    }
    cout << "\n";
  }
  return 0;
}
