#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  cin >> x;
}
template <typename T, typename T0>
void read(T &x, T0 &y) {
  cin >> x >> y;
}
template <typename T, typename T0, typename T1>
void read(T &x, T0 &y, T1 &z) {
  cin >> x >> y >> z;
}
bool prime(long long int a) {
  int p = sqrt(a);
  int q = 0;
  for (int i = 2; i <= p; ++i) {
    if (a % i == 0) {
      q++;
    }
  }
  if (q == 0) {
    return true;
  } else {
    return false;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int T;
  read(T);
  while (T--) {
    long long int n, j = 0;
    cin >> n;
    vector<long long int> nec(n), b(n), t;
    for (int i = 0; i < n; ++i) {
      cin >> nec[i];
    }
    for (int i = 0; i < n; ++i) {
      cin >> b[i];
    }
    sort(nec.begin(), nec.end());
    sort(b.begin(), b.end());
    for (int i = 0; i < n; ++i) {
      cout << nec[i] << " ";
    }
    cout << '\n';
    for (int i = 0; i < n; ++i) {
      cout << b[i] << " ";
    }
    cout << '\n';
  }
  return 0;
}
