#include <bits/stdc++.h>
using namespace std;
const long long INF = 5e18;
long long abbs(long long x) {
  if (x < 0) return -x;
  return x;
}
long long calc(long long a, long long b, long long c) {
  return (abbs(a - b) * abbs(a - b) + abbs(b - c) * abbs(b - c) +
          abbs(a - c) * abbs(a - c));
}
vector<long long> g[3];
long long bins(long long k, long long x, long long w, long long l,
               long long r) {
  if (l == r) {
    return g[k][l];
  }
  if (l + 1 == r) {
    if (x <= g[k][l]) return g[k][l];
    if (x >= g[k][r]) return g[k][r];
    if (w)
      return g[k][r];
    else
      return g[k][l];
  }
  long long md = (r + l) / 2;
  if (g[k][md] == x) return x;
  if (g[k][md] < x)
    return bins(k, x, w, md, r);
  else
    return bins(k, x, w, l, md);
}
void slv() {
  for (long long i = 0; i < 3; i++) g[i].clear();
  long long nr, ng, nb;
  cin >> nr >> ng >> nb;
  g[0] = vector<long long>(nr);
  g[1] = vector<long long>(ng);
  g[2] = vector<long long>(nb);
  ;
  {
    for (long long i = 0; i < nr; i++) cin >> g[0][i];
  };
  ;
  {
    for (long long i = 0; i < ng; i++) cin >> g[1][i];
  };
  ;
  {
    for (long long i = 0; i < nb; i++) cin >> g[2][i];
  };
  for (long long i = 0; i < 3; i++) sort(g[i].begin(), g[i].end());
  long long ans = INF;
  for (long long i = 0; i < 3; i++) {
    long long x, y, z;
    for (long long w = 0; w < 2; w++)
      for (long long fw = 0; fw < 2; fw++)
        for (long long j = 0; j < g[i].size(); j++) {
          x = g[i][j];
          long long sw = 1;
          for (long long k = 0; k < 3; k++) {
            if (k == i) continue;
            if (sw) {
              y = bins(k, x, w, 0, g[k].size() - 1);
              sw--;
            } else {
              z = bins(k, x, fw, 0, g[k].size() - 1);
            }
          }
          ans = min(ans, calc(x, y, z));
        }
  }
  cout << ans << '\n';
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie();
  ;
  long long t = 1;
  cin >> t;
  while (t--) {
    slv();
  }
}
