#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
const long long maxn = 2e5 + 7;
const long long mod = 1e9 + 7;
long long a[maxn];
long long b[maxn];
int32_t main() {
  long long q;
  cin >> q;
  while (q--) {
    long long n;
    cin >> n;
    for (long long i = 1; i <= n; i++) cin >> a[i];
    for (long long i = 1; i <= n; i++) cin >> b[i];
    sort(a + 1, a + 1 + n);
    sort(b + 1, b + 1 + n);
    for (long long i = 1; i <= n; i++) {
      cout << a[i] << " ";
    }
    cout << '\n';
    for (long long i = 1; i <= n; i++) cout << b[i] << " ";
    cout << '\n';
  }
}
