#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, x, k = 0;
  cin >> t;
  vector<int> v;
  vector<int> v1;
  while (t--) {
    cin >> n;
    for (int i = 0, j = 0; i < n; i++, j += k) {
      cin >> x;
      v.push_back(x);
    }
    for (int j = 0; j < n; j++) {
      cin >> x;
      v1.push_back(x);
    }
    sort(v.begin(), v.end());
    sort(v1.begin(), v1.end());
    for (int j = 0; j < n; j++) {
      cout << v[j] << " ";
      if (j == n - 1) cout << endl;
    }
    for (int j = 0; j < n; j++) {
      cout << v1[j] << " ";
      if (j == n - 1) cout << endl;
    }
    v.clear();
    v1.clear();
  }
  return 0;
}
