#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 7;
const int M = 4e5;
const int lim = 1e3;
const int p = 1e9 + 7;
const int inf = 0x3f3f3f3f;
int a[105], b[105];
int v1[1010], v2[1010];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    memset(v1, 0, sizeof(v1));
    memset(v2, 0, sizeof(v2));
    int n, cnt = 0, x;
    map<int, int> make_pair;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &x);
      v1[x]++;
    }
    for (int i = 1; i <= n; i++) {
      scanf("%d", &x);
      v2[x]++;
    }
    for (int i = 1; i <= 1000; i++) {
      while (v1[i]) {
        for (int j = 1; j <= 1000; j++) {
          if (v2[j] != 0 && make_pair[i + j] == 0) {
            make_pair[i + j] = 1;
            a[++cnt] = i;
            b[cnt] = j;
            v1[i]--;
            v2[j]--;
            if (v1[i] == 0) break;
          }
        }
      }
    }
    for (int i = 1; i <= n; i++) printf("%d ", a[i]);
    printf("\n");
    for (int i = 1; i <= n; i++) printf("%d ", b[i]);
    printf("\n");
  }
  return 0;
}
