#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t, nr, ng, nb;
  cin >> t;
  while (t--) {
    cin >> nr >> ng >> nb;
    vector<long long int> r(nr), g(ng), b(nb);
    for (int i = 0; i < int(nr); i++) cin >> r[i];
    for (int i = 0; i < int(ng); i++) cin >> g[i];
    for (int i = 0; i < int(nb); i++) cin >> b[i];
    sort(r.begin(), r.end());
    sort(g.begin(), g.end());
    sort(b.begin(), b.end());
    long long int respuesta = 4000000000000000000;
    long long int combinaciones[4];
    long long int maxg, ming, maxb, minb;
    int gM, gm, bM, bm;
    for (int i = 0; i < int(nr); i++) {
      gM = lower_bound(g.begin(), g.end(), r[i]) - g.begin();
      bM = lower_bound(b.begin(), b.end(), r[i]) - b.begin();
      gM = gM < ng ? gM : ng - 1;
      bM = bM < nb ? bM : nb - 1;
      maxg = g[gM];
      maxb = b[bM];
      gm = upper_bound(g.begin(), g.end(), r[i]) - g.begin();
      bm = upper_bound(b.begin(), b.end(), r[i]) - b.begin();
      if (gm) gm--;
      if (bm) bm--;
      ming = g[gm];
      minb = b[bm];
      combinaciones[0] = (r[i] - maxg) * (r[i] - maxg) +
                         (maxg - maxb) * (maxg - maxb) +
                         (maxb - r[i]) * (maxb - r[i]);
      combinaciones[1] = (r[i] - maxg) * (r[i] - maxg) +
                         (maxg - minb) * (maxg - minb) +
                         (minb - r[i]) * (minb - r[i]);
      combinaciones[2] = (r[i] - ming) * (r[i] - ming) +
                         (ming - maxb) * (ming - maxb) +
                         (maxb - r[i]) * (maxb - r[i]);
      combinaciones[3] = (r[i] - ming) * (r[i] - ming) +
                         (ming - minb) * (ming - minb) +
                         (minb - r[i]) * (minb - r[i]);
      for (int j = 0; j < int(4); j++)
        respuesta = min(respuesta, combinaciones[j]);
    }
    for (int i = 0; i < int(ng); i++) {
      gM = lower_bound(r.begin(), r.end(), g[i]) - r.begin();
      bM = lower_bound(b.begin(), b.end(), g[i]) - b.begin();
      gM = gM < nr ? gM : nr - 1;
      bM = bM < nb ? bM : nb - 1;
      maxg = r[gM];
      maxb = b[bM];
      gm = upper_bound(r.begin(), r.end(), g[i]) - r.begin();
      bm = upper_bound(b.begin(), b.end(), g[i]) - b.begin();
      if (gm) gm--;
      if (bm) bm--;
      ming = r[gm];
      minb = b[bm];
      combinaciones[0] = (g[i] - maxg) * (g[i] - maxg) +
                         (maxg - maxb) * (maxg - maxb) +
                         (maxb - g[i]) * (maxb - g[i]);
      combinaciones[1] = (g[i] - maxg) * (g[i] - maxg) +
                         (maxg - minb) * (maxg - minb) +
                         (minb - g[i]) * (minb - g[i]);
      combinaciones[2] = (g[i] - ming) * (g[i] - ming) +
                         (ming - maxb) * (ming - maxb) +
                         (maxb - g[i]) * (maxb - g[i]);
      combinaciones[3] = (g[i] - ming) * (g[i] - ming) +
                         (ming - minb) * (ming - minb) +
                         (minb - g[i]) * (minb - g[i]);
      for (int j = 0; j < int(4); j++)
        respuesta = min(respuesta, combinaciones[j]);
    }
    for (int i = 0; i < int(nb); i++) {
      gM = lower_bound(g.begin(), g.end(), b[i]) - g.begin();
      bM = lower_bound(r.begin(), r.end(), b[i]) - r.begin();
      gM = gM < ng ? gM : ng - 1;
      bM = bM < nr ? bM : nr - 1;
      maxg = g[gM];
      maxb = r[bM];
      gm = upper_bound(g.begin(), g.end(), b[i]) - g.begin();
      bm = upper_bound(r.begin(), r.end(), b[i]) - r.begin();
      if (gm) gm--;
      if (bm) bm--;
      ming = g[gm];
      minb = r[bm];
      combinaciones[0] = (b[i] - maxg) * (b[i] - maxg) +
                         (maxg - maxb) * (maxg - maxb) +
                         (maxb - b[i]) * (maxb - b[i]);
      combinaciones[1] = (b[i] - maxg) * (b[i] - maxg) +
                         (maxg - minb) * (maxg - minb) +
                         (minb - b[i]) * (minb - b[i]);
      combinaciones[2] = (b[i] - ming) * (b[i] - ming) +
                         (ming - maxb) * (ming - maxb) +
                         (maxb - b[i]) * (maxb - b[i]);
      combinaciones[3] = (b[i] - ming) * (b[i] - ming) +
                         (ming - minb) * (ming - minb) +
                         (minb - b[i]) * (minb - b[i]);
      for (int j = 0; j < int(4); j++)
        respuesta = min(respuesta, combinaciones[j]);
    }
    cout << respuesta << '\n';
  }
  return 0;
}
