#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int ti = 1; ti <= t; ti++) {
    int n, i;
    cin >> n;
    vector<int> a(n), b(n);
    for (i = 0; i < n; i++) cin >> a[i];
    for (i = 0; i < n; i++) cin >> b[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for (i = 0; i < n; i++) cout << a[i] << " ";
    cout << endl;
    for (i = 0; i < n; i++) cout << b[i] << " ";
    cout << endl;
  }
  return 0;
}
