#include <bits/stdc++.h>
char pbuf[1 << 20], *pp1 = pbuf;
inline void push(char c) {
  *pp1 = c;
  pp1 = (pp1 - pbuf == (1 << 20) - 1) ? (fwrite(pbuf, 1, 1 << 20, stdout), pbuf)
                                      : (pp1 + 1);
}
char *p1, *p2, buf[1 << 20];
using namespace std;
inline long long rd() {
  long long ans;
  char t, k;
  while (((t = (p1 == p2 && (p1 = buf, p2 = buf + fread(buf, 1, 1 << 20, stdin),
                             p1 == p2)
                    ? 0
                    : (*(p1++)))) != '-') &&
         (t > '9' || t < '0'))
    ;
  k = (t == '-');
  ans = k ? 0 : (t - '0');
  while ((t = (p1 == p2 && (p1 = buf, p2 = buf + fread(buf, 1, 1 << 20, stdin),
                            p1 == p2)
                   ? 0
                   : (*(p1++)))) >= '0' &&
         t <= '9')
    ans = ans * 10 + t - '0';
  return k ? -ans : ans;
}
inline void wt(long long k) {
  if (k < 0)
    push('-'), wt(-k);
  else {
    if (k < 10)
      push('0' + k);
    else
      wt(k / 10), push('0' + k % 10);
  }
  return;
}
const int maxn = 1e5 + 5;
int t, nr, ng, nb, r[maxn], g[maxn], b[maxn];
long long getans() {
  long long Ans = 3e18;
  for (register int i = (1); i <= (ng); ++i) {
    int rr = upper_bound(r + 1, r + nr + 1, g[i]) - r;
    if (rr == 1) continue;
    rr--;
    int bb = lower_bound(b + 1, b + nb + 1, g[i]) - b;
    if (bb == nb + 1) continue;
    Ans = min(Ans, (long long)(g[i] - r[rr]) * (g[i] - r[rr]) +
                       (long long)(r[rr] - b[bb]) * (r[rr] - b[bb]) +
                       (long long)(b[bb] - g[i]) * (b[bb] - g[i]));
  }
  return Ans;
}
int main() {
  t = rd();
  while (t--) {
    nr = rd(), ng = rd(), nb = rd();
    for (register int i = (1); i <= (nr); ++i) r[i] = rd();
    for (register int i = (1); i <= (ng); ++i) g[i] = rd();
    for (register int i = (1); i <= (nb); ++i) b[i] = rd();
    sort(r + 1, r + nr + 1);
    sort(g + 1, g + ng + 1);
    sort(b + 1, b + nb + 1);
    long long Ans = 3e18;
    Ans = min(Ans, getans());
    int n = max(nb, max(nr, ng));
    for (register int i = (1); i <= (n); ++i) swap(g[i], b[i]);
    swap(nb, ng);
    Ans = min(Ans, getans());
    for (register int i = (1); i <= (n); ++i) swap(r[i], b[i]);
    swap(nb, nr);
    Ans = min(Ans, getans());
    for (register int i = (1); i <= (n); ++i) swap(g[i], b[i]);
    swap(nb, ng);
    Ans = min(Ans, getans());
    for (register int i = (1); i <= (n); ++i) swap(r[i], b[i]);
    swap(nb, nr);
    Ans = min(Ans, getans());
    for (register int i = (1); i <= (n); ++i) swap(g[i], b[i]);
    swap(nb, ng);
    Ans = min(Ans, getans());
    cout << Ans << "\n";
  }
  fwrite(pbuf, 1, pp1 - pbuf, stdout);
  return 0;
}
