#include <bits/stdc++.h>
using namespace std;
int compare(const void* a, const void* b) {
  return (*(long long*)a - *(long long*)b);
}
int main() {
  long long p = 0, q = 0, r = 0, o = 0, g = 0, n, m = 1, w, k, l, d = 0, i,
            j = 1, flag = 0, t;
  cin >> t;
  while (t--) {
    cin >> n;
    long long a[n];
    long long b[n];
    for (i = 0; i < n; i++) cin >> a[i];
    for (i = 0; i < n; i++) cin >> b[i];
    qsort(a, n, sizeof(long long), compare);
    qsort(b, n, sizeof(long long), compare);
    for (i = 0; i < n; i++) {
      cout << a[i] << " ";
    }
    cout << endl;
    for (i = 0; i < n; i++) {
      cout << b[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
