#include <bits/stdc++.h>
using namespace std;
int a[1009], b[1009];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    for (int i = 0; i < n; i++) scanf("%d", &b[i]);
    sort(a, a + n);
    sort(b, b + n);
    for (int i = 0; i < n; i++) printf("%d%s", a[i], i == n - 1 ? "\n" : " ");
    for (int i = 0; i < n; i++) printf("%d%s", b[i], i == n - 1 ? "\n" : " ");
  }
  return 0;
}
