#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 50;
const int INF = 0x3f3f3f3f;
const double EXP = 1e-7;
inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int a[N], b[N];
int main() {
  int T = 1;
  T = read();
  while (T--) {
    int n;
    n = read();
    for (int i = 0; i < n; i++) a[i] = read();
    for (int i = 0; i < n; i++) b[i] = read();
    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;
}
