#include <bits/stdc++.h>
using namespace std;
int solve() {
  long long n;
  cin >> n;
  vector<long long int> a(n), b(n);
  for (long long int i = 0; i < n; i++) cin >> a[i];
  for (long long int i = 0; i < n; i++) cin >> b[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  for (long long int i = 0; i < n; i++) cout << a[i] << " ";
  cout << "\n";
  for (long long int i = 0; i < n; i++) cout << b[i] << " ";
  cout << "\n";
  return 0;
}
int main() {
  auto start = chrono::high_resolution_clock::now();
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long test_cases = 1;
  cin >> test_cases;
  while (test_cases--) solve();
  auto stop = chrono::high_resolution_clock::now();
  auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
}
