#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a;
vector<int> b;
long long answer;
void In() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  b.resize(n);
  for (int i = 0; i < n; i++) cin >> b[i];
}
void Solve() {
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
}
void Out() {
  for (int x : a) cout << x << " ";
  cout << endl;
  for (int x : b) cout << x << " ";
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    In();
    Solve();
    Out();
  }
}
