#include <bits/stdc++.h>
using namespace std;
long long int add(long long int a, long long int b) {
  a %= 1000000007;
  b %= 1000000007;
  return (a + b + 1000000007) % 1000000007;
}
long long int mul(long long int a, long long int b) {
  a %= 1000000007;
  b %= 1000000007;
  return (a * b + 1000000007) % 1000000007;
}
long long int power(long long int x, long long int n) {
  if (n == 0 || x == 1) return 1;
  long long int ans = power(x, n / 2) % 1000000007;
  if (n & 1)
    return (((ans * ans) % 1000000007) * (x % 1000000007)) % 1000000007;
  else
    return ((ans * ans) % 1000000007);
}
void solve() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int a[n];
    long long int b[n];
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (long long int i = 0; i < n; i++) cin >> b[i];
    sort(a, a + n);
    sort(b, b + n);
    for (long long int i = 0; i < n; i++) cout << a[i] << " ";
    cout << "\n";
    for (long long int i = 0; i < n; i++) cout << b[i] << " ";
    cout << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
