#include <bits/stdc++.h>
using namespace std;
int a[111], b[111];
int main() {
  ios::sync_with_stdio(false);
  int t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) cin >> b[i];
    sort(a + 1, a + n + 1);
    sort(b + 1, b + n + 1);
    for (int i = 1; i <= n; i++) cout << a[i] << " ";
    cout << endl;
    for (int i = 1; i <= n; i++) cout << b[i] << " ";
    cout << endl;
  }
  return 0;
}
