#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
template <typename T>
inline T getNum() {
  T k = 0;
  char c = getchar(), f = 1;
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) k = k * 10 + c - '0';
  return k * f;
}
clock_t opt, edt;
inline void init() {}
inline void tini() {}
const int maxn = 2e5 + 30;
vector<int> a, b;
int n, flag;
int main() {
  init();
  int t = getNum<int>();
  while (t--) {
    n = getNum<int>();
    a.clear(), b.clear();
    for (int i = 1; i <= n; i++) a.push_back(getNum<int>());
    for (int i = 1; i <= n; i++) b.push_back(getNum<int>());
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for (int i = 0; i < n; i++) cout << a[i] << ' ';
    putchar('\n');
    for (int i = 0; i < n; i++) cout << b[i] << ' ';
    putchar('\n');
  }
  tini();
}
