#include <bits/stdc++.h>
const int MAXN = 3e5 + 10;
const double eps = 1e-8;
using namespace std;
struct edge {
  int t, v;
  edge *next;
} e[MAXN << 1], *h[MAXN], *o = e;
void add(int x, int y, int vul) {
  o->t = y;
  o->v = vul;
  o->next = h[x];
  h[x] = o++;
}
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
int _, n, a[MAXN], b[MAXN];
bool vis[MAXN], pis[MAXN];
int ans1[MAXN], ans2[MAXN];
int main() {
  _ = read();
  while (_--) {
    n = read();
    for (int i = 1; i <= n; i++) pis[i] = 0;
    for (int i = 1; i <= n; i++) a[i] = read();
    for (int i = 1; i <= n; i++) b[i] = read();
    sort(a + 1, a + n + 1);
    sort(b + 1, b + n + 1);
    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;
}
