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