#include <bits/stdc++.h>
int read() {
  static int c, x;
  while ((c = getchar()) < 48) {
  }
  x = c & 15;
  while ((c = getchar()) >= 48) x = x * 10 + (c & 15);
  return x;
}
const long long INFLL = 0x3f3f3f3f3f3f3f3f;
long long ans;
int a[100010], b[100010], c[100010];
inline void upd(const int &x, const int &y, const int &z) {
  if (y && z) {
    ans = std::min(ans, 1ll * (x - y) * (x - y) + 1ll * (y - z) * (y - z) +
                            1ll * (z - x) * (z - x));
  }
}
int main() {
  for (int T = read(); T--;) {
    const int na = read(), nb = read(), nc = read();
    for (int i = 1; i <= na; ++i) a[i] = read();
    for (int i = 1; i <= nb; ++i) b[i] = read();
    for (int i = 1; i <= nc; ++i) c[i] = read();
    std::sort(a + 1, a + na + 1);
    std::sort(b + 1, b + nb + 1);
    std::sort(c + 1, c + nc + 1);
    a[na + 1] = 0;
    b[nb + 1] = 0;
    c[nc + 1] = 0;
    ans = INFLL;
    for (int i = 1; i <= na; ++i) {
      const int lb = *(std::upper_bound(b + 1, b + nb + 1, a[i]) - 1);
      const int hb = *std::lower_bound(b + 1, b + nb + 1, a[i]);
      const int lc = *(std::upper_bound(c + 1, c + nc + 1, a[i]) - 1);
      const int hc = *std::lower_bound(c + 1, c + nc + 1, a[i]);
      upd(a[i], lb, hc);
      upd(a[i], lc, hb);
    }
    for (int i = 1; i <= nb; ++i) {
      const int la = *(std::upper_bound(a + 1, a + na + 1, b[i]) - 1);
      const int ha = *std::lower_bound(a + 1, a + na + 1, b[i]);
      const int lc = *(std::upper_bound(c + 1, c + nc + 1, b[i]) - 1);
      const int hc = *std::lower_bound(c + 1, c + nc + 1, b[i]);
      upd(b[i], la, hc);
      upd(b[i], lc, ha);
    }
    for (int i = 1; i <= nc; ++i) {
      const int la = *(std::upper_bound(a + 1, a + na + 1, c[i]) - 1);
      const int ha = *std::lower_bound(a + 1, a + na + 1, c[i]);
      const int lb = *(std::upper_bound(b + 1, b + nb + 1, c[i]) - 1);
      const int hb = *std::lower_bound(b + 1, b + nb + 1, c[i]);
      upd(c[i], la, hb);
      upd(c[i], lb, ha);
    }
    printf("%lld\n", ans);
  }
  return 0;
}
