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