#include <bits/stdc++.h>
using namespace std;
int main() {
  int TestCase;
  cin >> TestCase;
  while (TestCase--) {
    int num;
    cin >> num;
    int array1[num], array2[num];
    for (int i = 0; i < num; i++) {
      cin >> array1[i];
    }
    sort(array1, array1 + num);
    for (int i = 0; i < num; i++) {
      cin >> array2[i];
    }
    sort(array2, array2 + num);
    for (int i = 0; i < num - 1; i++) {
      if ((array1[i] + array2[i]) == (array1[i + 1] + array2[i + 1])) {
        int temp = array1[i];
        array1[i] = array1[i + 1];
        array1[i + 1] = temp;
      }
    }
    for (int i = 0; i < num; i++) {
      cout << array1[i] << " ";
    }
    cout << endl;
    for (int i = 0; i < num; i++) {
      cout << array2[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
