#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int tt = 1; tt <= t; tt++) {
    int r[100005], g[100005], b[100005];
    int nr, ng, nb;
    cin >> nr >> ng >> nb;
    for (int i = 0; i < nr; i++) cin >> r[i];
    for (int i = 0; i < ng; i++) cin >> g[i];
    for (int i = 0; i < nb; i++) cin >> b[i];
    sort(r, r + nr);
    sort(g, g + ng);
    sort(b, b + nb);
    long long int ans = LONG_LONG_MAX;
    for (int i = 0; i < nr; i++) {
      int x = r[i];
      auto y = upper_bound(g, g + ng, x);
      if (y == g + ng) y--;
      auto y2 = y;
      if (y - g != 0) {
        y2--;
      }
      auto z = upper_bound(b, b + nb, x);
      if (z == b + nb) z--;
      auto z2 = z;
      if (z - b != 0) {
        z2--;
      }
      ans = min(ans, (x - (*y)) * 1LL * (x - *y) + (x - *z) * 1LL * (x - *z) +
                         (*z - *y) * 1LL * (*z - *y));
      ans = min(ans, (x - (*y2)) * 1LL * (x - *y2) + (x - *z) * 1LL * (x - *z) +
                         (*z - *y2) * 1LL * (*z - *y2));
      ans =
          min(ans, (x - (*y2)) * 1LL * (x - *y2) + (x - *z2) * 1LL * (x - *z2) +
                       (*z2 - *y2) * 1LL * (*z2 - *y2));
      ans = min(ans, (x - (*y)) * 1LL * (x - *y) + (x - *z2) * 1LL * (x - *z2) +
                         (*z2 - *y) * 1LL * (*z2 - *y));
    }
    for (int i = 0; i < ng; i++) {
      int x = g[i];
      auto y = upper_bound(r, r + nr, x);
      if (y == r + nr) y--;
      auto y2 = y;
      if (y - r != 0) {
        y2--;
      }
      auto z = upper_bound(b, b + nb, x);
      if (z == b + nb) z--;
      auto z2 = z;
      if (z - b != 0) {
        z2--;
      }
      ans = min(ans, (x - (*y)) * 1LL * (x - *y) + (x - *z) * 1LL * (x - *z) +
                         (*z - *y) * 1LL * (*z - *y));
      ans = min(ans, (x - (*y2)) * 1LL * (x - *y2) + (x - *z) * 1LL * (x - *z) +
                         (*z - *y2) * 1LL * (*z - *y2));
      ans =
          min(ans, (x - (*y2)) * 1LL * (x - *y2) + (x - *z2) * 1LL * (x - *z2) +
                       (*z2 - *y2) * 1LL * (*z2 - *y2));
      ans = min(ans, (x - (*y)) * 1LL * (x - *y) + (x - *z2) * 1LL * (x - *z2) +
                         (*z2 - *y) * 1LL * (*z2 - *y));
    }
    for (int i = 0; i < nb; i++) {
      int x = b[i];
      auto y = upper_bound(g, g + ng, x);
      if (y == g + ng) y--;
      auto y2 = y;
      if (y - g != 0) {
        y2--;
      }
      auto z = upper_bound(r, r + nr, x);
      if (z == r + nr) z--;
      auto z2 = z;
      if (z - r != 0) {
        z2--;
      }
      ans = min(ans, (x - (*y)) * 1LL * (x - *y) + (x - *z) * 1LL * (x - *z) +
                         (*z - *y) * 1LL * (*z - *y));
      ans = min(ans, (x - (*y2)) * 1LL * (x - *y2) + (x - *z) * 1LL * (x - *z) +
                         (*z - *y2) * 1LL * (*z - *y2));
      ans =
          min(ans, (x - (*y2)) * 1LL * (x - *y2) + (x - *z2) * 1LL * (x - *z2) +
                       (*z2 - *y2) * 1LL * (*z2 - *y2));
      ans = min(ans, (x - (*y)) * 1LL * (x - *y) + (x - *z2) * 1LL * (x - *z2) +
                         (*z2 - *y) * 1LL * (*z2 - *y));
    }
    cout << ans << "\n";
  }
  return 0;
}
