#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, i = 0, j = 0, k = 0, l = 0, m = 0, a = 0, b = 0, sum = 0, x = 0,
               y = 0, z = 0, c, p;
  cin >> c;
  while (c--) {
    cin >> n;
    long long arr[n], brr[n];
    for (i = 0; i < n; i++) {
      cin >> arr[i];
    }
    for (i = 0; i < n; i++) {
      cin >> brr[i];
    }
    sort(arr, arr + n);
    sort(brr, brr + n);
    for (i = n - 1; i >= 0; i--) {
      cout << arr[i] << " ";
    }
    cout << endl;
    for (i = n - 1; i >= 0; i--) {
      cout << brr[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
