#include <bits/stdc++.h>
const long long N = 500010, INF = 6e18;
long long a[N], b[N], c[N];
long long asize, bsize, csize;
long long T;
long long minx;
inline long long read(void) {
  long long res, f = 1;
  char c;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') f = -1;
  res = c - 48;
  while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - 48;
  return res * f;
}
inline long long pre(long long *ar, long long size, long long x) {
  long long ans = std::lower_bound(ar + 1, ar + 1 + size, x) - ar;
  if (ans > size) return 0;
  return ar[ans];
}
inline long long nxt(long long *ar, long long size, long long x) {
  long long ans = std::upper_bound(ar + 1, ar + 1 + size, x) - ar - 1;
  if (ans > size || ans < 1) return 0;
  return ar[ans];
}
inline long long p(long long x) { return x * x; }
inline void cmin(long long x, long long y, long long z) {
  if (x && y && z) minx = std::min(minx, p(x - y) + p(y - z) + p(z - x));
  return;
}
signed main(void) {
  T = read();
  while (T--) {
    asize = read(), bsize = read(), csize = read();
    for (register long long i = 1; i <= asize; ++i) {
      a[i] = read();
    }
    for (register long long i = 1; i <= bsize; ++i) {
      b[i] = read();
    }
    for (register long long i = 1; i <= csize; ++i) {
      c[i] = read();
    }
    std::sort(a + 1, a + 1 + asize);
    std::sort(b + 1, b + 1 + bsize);
    std::sort(c + 1, c + 1 + csize);
    minx = INF;
    for (register long long i = 1; i <= asize; ++i) {
      long long va = pre(b, bsize, a[i]), vb = nxt(b, bsize, a[i]);
      cmin(a[i], va, pre(c, csize, (a[i] + va) / 2));
      cmin(a[i], va, nxt(c, csize, (a[i] + va) / 2));
      cmin(a[i], vb, pre(c, csize, (a[i] + vb) / 2));
      cmin(a[i], vb, nxt(c, csize, (a[i] + vb) / 2));
      va = pre(c, csize, a[i]), vb = nxt(c, csize, a[i]);
      cmin(a[i], pre(b, bsize, (a[i] + va) / 2), va);
      cmin(a[i], nxt(b, bsize, (a[i] + va) / 2), va);
      cmin(a[i], pre(b, bsize, (a[i] + vb) / 2), vb);
      cmin(a[i], nxt(b, bsize, (a[i] + vb) / 2), vb);
    }
    std::cout << minx << std::endl;
  }
  return 0;
}
