#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
int n, m, a[maxn], t, k, b[maxn], c[maxn], d[maxn], cnt[maxn], ac[maxn],
    bc[maxn];
bool dfs(int k) {
  if (k == n + 1) return true;
  for (int i = 1; i <= n; ++i) {
    if (ac[i]) continue;
    for (int j = 1; j <= n; ++j) {
      if (bc[j]) continue;
      if (cnt[a[i] + b[j]]) continue;
      c[k] = a[i], d[k] = b[j];
      cnt[a[i] + b[j]] = ac[i] = bc[j] = 1;
      if (dfs(k + 1)) return true;
      cnt[a[i] + b[j]] = ac[i] = bc[j] = 0;
    }
  }
  return false;
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &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]);
    puts("");
    for (int i = 1; i <= n; ++i) printf("%d ", b[i]);
    puts("");
  }
  return 0;
}
