#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e6 + 1e5;
const int mod = 1e9 + 7;
const double PI = atan2(0, -1);
void time() { cerr << (double)clock() / CLOCKS_PER_SEC << '\n'; }
void precalc() {}
void solve() {
  int n;
  cin >> n;
  int a[n], b[n];
  for (auto &i : a) cin >> i;
  for (auto &i : b) cin >> i;
  sort((a), (a) + (n));
  sort((b), (b) + (n));
  for (auto &i : a) cout << i << ' ';
  cout << '\n';
  for (auto &i : b) cout << i << ' ';
  cout << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  precalc();
  int t;
  t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
