#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 10;
int a[N], b[N];
int main() {
  int n, t, i;
  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 - 1; i++) cout << a[i] << " ";
    cout << a[n - 1] << endl;
    for (i = 0; i < n - 1; i++) cout << b[i] << " ";
    cout << b[n - 1] << endl;
  }
  return 0;
}
