#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> a(n), b(n);
    for (auto &it : a) cin >> it;
    for (auto &it : b) cin >> it;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for (auto &it : a) {
      cout << it << " ";
    }
    cout << "\n";
    for (auto &it : b) {
      cout << it << " ";
    }
    cout << "\n";
  }
  return 0;
}
