#include <bits/stdc++.h>
using namespace std;
map<int, int> d;
int main() {
  int t, n, x;
  vector<int> a, b;
  vector<pair<int, int> > c;
  cin >> t;
  while (t--) {
    a.clear();
    b.clear();
    c.clear();
    d.clear();
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> x;
      a.push_back(x);
    }
    for (int i = 0; i < n; i++) cin >> x, b.push_back(x);
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (b[j] > 0 && d[a[i] + b[j]] == 0) {
          d[a[i] + b[j]] = 1;
          c.push_back(make_pair(a[i], b[j]));
          b[j] = 0;
          break;
        }
      }
    }
    for (int i = 0; i < n; i++) cout << c[i].first << ' ';
    cout << endl;
    for (int i = 0; i < n; i++) cout << c[i].second << ' ';
    cout << endl;
  }
  return 0;
}
