#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 1;
const long long M = 1e3 + 1;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n + 1];
    long long b[n + 1];
    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";
  }
}
