#include <bits/stdc++.h>
using namespace std;
const int Z = (int)1e3 + 228;
const int N = (int)1e5 + 228;
const int INF = (int)1e9 + 228;
const int MOD = (int)1e9 + 7;
const long long LLINF = (long long)1e18 + 228;
const long double eps = (long double)1e-6;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    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 << "\n";
    for (int i = 0; i < n; i++) {
      cout << b[i] << ' ';
    }
    cout << "\n";
  }
  return 0;
}
