#include <bits/stdc++.h>
using namespace std;
int main() {
  int no_of_daught, *necklace, *bracelet, test_cases;
  cin >> test_cases;
test:
  cin >> no_of_daught;
  necklace = new int[no_of_daught];
  bracelet = new int[no_of_daught];
  for (int i = 0; i < no_of_daught; i++) cin >> necklace[i];
  for (int i = 0; i < no_of_daught; i++) cin >> bracelet[i];
  sort(necklace, necklace + no_of_daught);
  sort(bracelet, bracelet + no_of_daught);
  for (int i = 0; i < no_of_daught; i++) cout << necklace[i] << " ";
  cout << endl;
  for (int i = 0; i < no_of_daught; i++) cout << bracelet[i] << " ";
  delete[] bracelet;
  delete[] necklace;
  test_cases--;
  if (test_cases > 0) goto test;
  return 0;
}
