#include <bits/stdc++.h>
using namespace std;
unordered_map<int, int> mp;
void resolve_conflict(int necklaces[], int bracelet_ans[], int conflict_idx) {
  int other_idx = mp[necklaces[conflict_idx] + bracelet_ans[conflict_idx]];
  if (other_idx > conflict_idx) swap(other_idx, conflict_idx);
  int tmp = bracelet_ans[conflict_idx];
  bracelet_ans[conflict_idx] = bracelet_ans[other_idx];
  bracelet_ans[other_idx] = tmp;
  int sum1 = necklaces[conflict_idx] + bracelet_ans[conflict_idx];
  int sum2 = necklaces[other_idx] + bracelet_ans[other_idx];
  if (mp.find(sum2) != mp.end()) {
    resolve_conflict(necklaces, bracelet_ans, other_idx);
  } else {
    mp[sum2] = other_idx;
  }
  if (mp.find(sum1) != mp.end()) {
    resolve_conflict(necklaces, bracelet_ans, conflict_idx);
  } else {
    mp[sum1] = conflict_idx;
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    mp.clear();
    int n;
    cin >> n;
    int necklaces[n];
    int bracelets[n];
    for (int i = 0; i < n; i++) cin >> necklaces[i];
    for (int i = 0; i < n; i++) cin >> bracelets[i];
    sort(necklaces, necklaces + n);
    sort(bracelets, bracelets + n);
    for (int i = 0; i < n; i++) cout << necklaces[i] << " ";
    cout << endl;
    for (int i = 0; i < n; i++) cout << bracelets[i] << " ";
    cout << endl;
  }
}
