#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, cnt = 1;
string s;
bool ok = true, mtest = true;
void solve() {
  cin >> b;
  vector<int> v(b), vc(b);
  for (auto& i : v) cin >> i;
  for (auto& i : vc) cin >> i;
  sort(v.begin(), v.end());
  sort(vc.begin(), vc.end());
  for (auto i : v) cout << i << ' ';
  cout << '\n';
  for (auto i : vc) cout << i << ' ';
  cout << '\n';
}
int main() {
  cin >> a;
  while (a--) solve();
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
