#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma loop_opt(on)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
constexpr ll MAX = 1e6 + 5;
constexpr ll MOD = 998244353;
ll fpow(ll b, ll a, ll mod = MOD) {
  b %= mod;
  ll r = 1;
  for (; a; b = b * b % mod, a >>= 1) a & 1 && (r = r * b % mod);
  return r;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  int T;
  cin >> T;
  for (auto t = 0; t < T; ++t) {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int &x : a) cin >> x;
    for (int &x : b) cin >> x;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for (auto i = 1; i < n; ++i)
      if (a[i] + b[i] == a[i - 1] + b[i - 1]) swap(b[i], b[i - 1]);
    for (int x : a) cout << x << ' ';
    cout << '\n';
    for (int x : b) cout << x << ' ';
    cout << '\n';
  }
}
