#include <bits/stdc++.h>
using namespace std;
int r[] = {1, -1, 0, 0};
int c[] = {0, 0, 1, -1};
int x[] = {0, 0, 1, -1, -1, 1, -1, 1};
int y[] = {-1, 1, 0, 0, 1, 1, -1, -1};
int kx[] = {-2, -2, -1, -1, 1, 1, 2, 2};
int ky[] = {-1, 1, -2, 2, -2, 2, -1, 1};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t, n;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    int a[n], b[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 ", a[i]);
    printf("\n");
    for (int i = 0; i < n; i++) printf("%d ", b[i]);
    printf("\n");
  }
  return 0;
}
