#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, i, j;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> m;
    int a[m], b[m];
    for (j = 0; j < m; j++) {
      cin >> a[j];
    }
    for (j = 0; j < m; j++) {
      cin >> b[j];
    }
    sort(a, a + m);
    sort(b, b + m);
    for (j = 0; j < m; j++) {
      cout << a[j] << " ";
    }
    cout << endl;
    for (j = 0; j < m; j++) {
      cout << b[j] << " ";
    }
    cout << endl;
  }
}
