#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  int t;
  cin >> t;
  for (int tt = 0; tt < (t); ++tt) {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < (n); ++i) cin >> a[i];
    for (int i = 0; i < (n); ++i) cin >> b[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for (int i = 0; i < (n); ++i) cout << a[i] << " ";
    cout << '\n';
    for (int i = 0; i < (n); ++i) cout << b[i] << " ";
    cout << '\n';
  }
  return 0;
}
