#include <bits/stdc++.h>
using namespace std;
int main() {
  int z2, m, i1, i2, ind, i, t, tl, x1 = 1, q, o1, o2, e1, k, e2, k1, k2, t1, d,
                                    j, o, e, f, h2, l1, l2, m1, m2, odd, n, n2,
                                    ans, x, y;
  unsigned long long int a[200], b[200], mn, mx;
  cin >> t;
  while (t--) {
    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 << "\n";
    for (i = 0; i < n; i++) {
      cout << b[i] << " ";
    }
    cout << "\n";
  }
  return 0;
}
