#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 7;
const long long inf = 1e9;
const long long eps = 1e-12;
long long a[N], b[N], used[N], ans[N];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  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 + n + 1);
    sort(b + 1, b + n + 1);
    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';
  }
}
