#include <bits/stdc++.h>
using namespace std;
const unsigned long long p1 = 131;
const unsigned long long p2 = 129;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int infi = 2 * 1e9;
const long long inf = 9223372036854775807;
const long long dd = 1e3 + 7;
const long long MOD = 998244353;
int a, b, cur;
const int mod = 1791791791;
int NextRand() {
  cur = (cur * a + b) % mod;
  return cur;
}
int main() {
  ios_base::sync_with_stdio(0);
  ;
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> 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 << endl;
    for (int i = 0; i < n; i++) cout << b[i] << ' ';
    cout << endl;
  }
  return 0;
}
