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