#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    vector<pair<int, int> > ans(n);
    for (int i = 0; i < n; i++) ans[i] = {a[i], b[i]};
    for (int i = 0; i < n; i++) cout << ans[i].first << " \n"[i == n];
    for (int i = 0; i < n; i++) cout << ans[i].second << " \n"[i == n];
  }
  return 0;
}
