#include <bits/stdc++.h>
using namespace std;
long long q;
signed main() {
  ios_base::sync_with_stdio(0);
  cin >> q;
  while (q--) {
    long long n;
    cin >> n;
    vector<pair<long long, long long>> a(n), b(n);
    for (long long i = 0; i < n; ++i) {
      cin >> a[i].first;
      a[i].second = i;
    }
    for (long long i = 0; i < n; ++i) {
      cin >> b[i].first;
      b[i].second = i;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    vector<long long> res(n);
    for (long long i = 0; i < n; ++i) cout << a[i].first << ' ';
    cout << '\n';
    for (long long i = 0; i < n; ++i) cout << b[i].first << ' ';
    cout << '\n';
  }
}
