#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int _, a[N], b[N], n;
void sol() {
  scanf("%d", &n);
  for (int i = (int)(0); i < (int)(n); i++) scanf("%d", a + i);
  for (int i = (int)(0); i < (int)(n); i++) scanf("%d", b + i);
  sort(a, a + n);
  sort(b, b + n);
  for (int i = (int)(0); i < (int)(n); i++) printf("%d ", a[i]);
  puts("");
  for (int i = (int)(0); i < (int)(n); i++) printf("%d ", b[i]);
  puts("");
}
int main() {
  scanf("%d", &_);
  for (; _; _--) sol();
}
