#include <bits/stdc++.h>
using namespace std;
void Solve() {
  long long int n;
  cin >> n;
  long long int *a = new long long int[n];
  long long int *b = new long long int[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
  sort(b, b + n);
  for (int i = 0; i < n; i++) {
    cout << b[i] << " ";
  }
  cout << endl;
  delete[] a;
  a = NULL;
  delete[] b;
  b = NULL;
}
long long int n;
int main() {
  cin >> n;
  while (n--) {
    Solve();
  }
  return 0;
}
