#include <bits/stdc++.h>
long long a[10001];
long long b[10001];
long long c[10001];
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
      cin >> b[i];
    }
    for (int i = 0; i < n; i++) {
      c[i] = a[i] + b[i];
    }
    int bb = 0, ii = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (c[i] == c[j] && i != j) {
          ii = i;
          bb++;
          break;
        }
      }
    }
    if (bb == 0) {
      for (int i = 0; i < n; i++) {
        cout << a[i] << " ";
      }
      cout << "\n";
      ;
      for (int i = 0; i < n; i++) {
        cout << b[i] << " ";
      }
      cout << "\n";
      ;
      continue;
    } else {
      sort(a, a + n);
      sort(b, b + n);
      int x = 0;
      for (int i = 0; i < n; i++) {
        c[i] = a[i] + b[i];
      }
      for (int i = 0; i < n; i++) {
        cout << a[i] << " ";
      }
      cout << "\n";
      ;
      for (int i = 0; i < n; i++) {
        cout << b[i] << " ";
      }
      cout << "\n";
      ;
    }
  }
}
