#include <bits/stdc++.h>
using namespace std;
map<int, int> mp1;
int a[120000];
int b[120000];
int vis[120];
struct node {
  int x, y;
} w[1200];
int main() {
  int T;
  cin >> T;
  while (T--) {
    int q = 0;
    memset(vis, 0, sizeof(vis));
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
      cin >> b[i];
    }
    sort(a, a + n);
    sort(b, b + n);
    for (int i = 0; i < n; i++) {
      printf("%d ", a[i]);
    }
    cout << endl;
    for (int i = 0; i < n; i++) {
      printf("%d ", b[i]);
    }
    cout << endl;
  }
  return 0;
}
