#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
  x = 0;
  int ch = getchar(), f = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  if (f) x = -x;
}
const int inf = 0x3f3f3f3f;
const int maxn = 1050;
int T, n, a[maxn], b[maxn];
int main() {
  cin >> T;
  while (T--) {
    cin >> n;
    for (int i = 1; i <= n; i++) read(a[i]);
    for (int i = 1; i <= n; i++) read(b[i]);
    sort(a + 1, a + n + 1);
    sort(b + 1, b + n + 1);
    for (int i = 1; i <= n; i++) cout << a[i] << " ";
    cout << endl;
    for (int i = 1; i <= n; i++) cout << b[i] << " ";
    cout << endl;
  }
  return 0;
}
