#include <bits/stdc++.h>
using namespace std;
using cat = long long;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(10);
  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(begin(A), end(A));
    sort(begin(B), end(B));
    for (int i = 0; i < N; i++) cout << A[i] << ((i == N - 1) ? "\n" : " ");
    for (int i = 0; i < N; i++) cout << B[i] << ((i == N - 1) ? "\n" : " ");
  }
  return 0;
}
