#include <bits/stdc++.h>
using namespace std;
const long long int prm1 = 95676260903887607;
const long long int prm2 = 999998727899999;
const long long int prm3 = 1012345678901;
const int prm4 = 2147483647;
const int prm5 = 998244353;
const int prm6 = 999999937;
const int prm7 = 9699690;
const int maxn = 105;
int a[maxn];
int b[maxn];
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    sort(a, a + n);
    sort(b, b + n);
    for (int i = 0; i < n; i++) cout << a[i] << ' ';
    cout << '\n';
    for (int i = 0; i < n; i++) cout << b[i] << ' ';
    cout << '\n';
  }
  return 0;
}
