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