#include <bits/stdc++.h>
using namespace std;
const long long LINF = LLONG_MAX;
const int INF = INT_MAX;
const int MOD = 998244353;
template <typename T>
void read(vector<T>& a) {
  for (auto& v : a) cin >> v;
}
void solve() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  read(a);
  read(b);
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  for (auto& v : a) cout << v << ' ';
  cout << '\n';
  for (auto& v : b) cout << v << ' ';
  cout << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  int q;
  cin >> q;
  while (q--) solve();
}
