#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d, x;
  vector<int> a;
  vector<int> b;
  cin >> n;
  while (n--) {
    a.clear();
    b.clear();
    cin >> d;
    for (int i = 0; i < d; i++) {
      cin >> x;
      a.push_back(x);
    }
    for (int i = 0; i < d; i++) {
      cin >> x;
      b.push_back(x);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for (int i = 0; i < d; i++) {
      cout << a[i] << " ";
    }
    cout << endl;
    for (int i = 0; i < d; i++) {
      cout << b[i] << " ";
    }
    cout << endl;
  }
}
