#include <bits/stdc++.h>
using namespace std;
string s1, s2, s3;
string s;
int main() {
  long long int a[20001] = {0}, v, b[10001], c = 0, d = 0, e, f, g, h, i, j,
                k = 0, l = 0, m, r, n, p = 0, q, t, ct = 0, ct1 = 0, ct2 = 0,
                ck = 0, ck1 = 0, ck2 = 0, ln, ln1, start, end, mid;
  long long int a1 = 0, cnt = 0, a2 = 0, a3 = 0, a4 = 0, sum = 0, sum1 = 0,
                max1, max2, min1, min2;
  double x, y, z;
  string jo, lo, ko;
  char st[1001], ch, ch1, ch2;
  cin >> d;
  while (d--) {
    cin >> n;
    for (i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (i = 0; i < n; i++) {
      cin >> b[i];
    }
    sort(a, a + n);
    sort(b, b + n);
    for (i = 0; i < n; i++) {
      cout << a[i] << " ";
    }
    cout << endl;
    for (i = 0; i < n; i++) {
      cout << b[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
