#include <bits/stdc++.h>
using namespace std;
int a[109], b[109];
map<int, int> freq;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> 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);
    bool x = 1;
    for (int i = 0; i < n; ++i) {
      int sum = a[i] + b[i];
      ++freq[sum];
      if (freq[sum] > 1) x = 0;
    }
    if (x) {
      for (int i = 0; i < n; ++i) cout << a[i] << " ";
      cout << "\n";
      for (int i = 0; i < n; ++i) cout << b[i] << " ";
      cout << "\n";
    } else {
      for (int i = 0; i < n; ++i) cout << a[i] << " ";
      cout << "\n";
      for (int i = n - 1; i >= 0; --i) cout << b[i] << " ";
      cout << "\n";
    }
    freq.clear();
  }
  return 0;
}
