#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,-O3")
using namespace std;
inline long long time() {
  return chrono ::system_clock().now().time_since_epoch().count();
}
mt19937 rnd(time());
mt19937_64 RND(time());
template <typename t>
inline void umin(t &a, t b) {
  a = min(a, b);
}
template <typename t>
inline void umax(t &a, t b) {
  a = max(a, b);
}
const int N = 2e5 + 5;
const int md = 998244353;
const int oo = 2e9;
const long long OO = 4e18;
void solve() {
  int t;
  cin >> t;
  for (; t--;) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    vector<int> b(n);
    for (int i = 0; i < n; ++i) cin >> b[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for (int i = 0; i < n; ++i) cout << a[i] << ' ';
    cout << endl;
    for (int i = 0; i < n; ++i) cout << b[i] << ' ';
    cout << endl;
  }
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
