#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int maxn = (long long int)2e5 + 5;
bool vis[2005];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n + 3], b[n + 3];
    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 - 1; i++) {
      if (vis[a[i] + b[i]]) {
        swap(b[i], b[i + 1]);
        vis[a[i] + b[i]];
      } else
        vis[a[i] + b[i]] = 1;
    }
    for (int i = 0; i < n; i++) cout << a[i] << " ";
    cout << endl;
    for (int i = 0; i < n; i++) cout << b[i] << " ";
    cout << endl;
    memset(vis, 0, sizeof(vis));
  }
  return 0;
}
