#include <bits/stdc++.h>
using namespace std;
const int MAX = (1e5) + 10;
int ara[MAX], bra[MAX];
void solve() {
  int n;
  cin >> n;
  for (int i = 0; i <= n - 1; i++) cin >> ara[i];
  for (int i = 0; i <= n - 1; i++) cin >> bra[i];
  sort(ara, ara + n);
  sort(bra, bra + n);
  for (int i = 0; i <= n - 1; i++) cout << ara[i] << " ";
  cout << endl;
  for (int i = 0; i <= n - 1; i++) cout << bra[i] << " ";
  cout << endl;
  return;
}
int main() {
  ios::sync_with_stdio(false);
  int tc;
  cin >> tc;
  for (int tt = 1; tt <= tc; tt++) solve();
  return 0;
}
