#include <bits/stdc++.h>
using namespace std;
long long a[120], b[120];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    for (long long i = 0; i < n; i++) cin >> a[i];
    for (long long i = 0; i < n; i++) cin >> b[i];
    sort(a, a + n);
    sort(b, b + n);
    for (long long i = 0; i < n; i++) cout << a[i] << ' ';
    cout << '\n';
    for (long long i = 0; i < n; i++) cout << b[i] << ' ';
    cout << '\n';
  }
  return 0;
}
