#include <bits/stdc++.h>
using namespace std;
void sieve(long long int n) {
  long long int i, j, k;
  bool prime[n + 1];
  vector<long long int> primeByIndex;
  memset(prime, true, n + 1);
  for (i = 2; i <= n; i++) {
    if (prime[i]) {
      for (j = i + i; j <= n; j = j + i) {
        prime[j] = false;
      }
    }
  }
  for (i = 2; i <= n; i++)
    if (prime[i]) primeByIndex.push_back(i);
}
bool sortbysec(const pair<long long int, long long int> &a,
               const pair<long long int, long long int> &b) {
  return (a.second < b.second);
}
void solve() {
  long long int i, j, k, n;
  cin >> n;
  vector<long long int> a(n), b(n);
  string s;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) cin >> b[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  for (i = 0; i < n; i++) cout << a[i] << " ";
  cout << "\n";
  for (i = 0; i < n; i++) cout << b[i] << " ";
  cout << "\n";
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int t;
  cin >> t;
  while (t--) solve();
}
