#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int test;
  cin >> test;
  for (int tst = 1; tst <= test; ++tst) {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < n; ++i) cin >> b[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for (int i = 0; i < n; ++i) cout << a[i] << " ";
    cout << endl;
    for (int i = 0; i < n; ++i) cout << b[i] << " ";
    cout << endl;
  }
  return 0;
}
