#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = 8e18;
void print() {}
template <class H, class... T>
void print(H&& h, T&&... t) {
  cout << h << " \n"[sizeof...(t) == 0];
  print(forward<T>(t)...);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll t;
  cin >> t;
  while (t--) {
    ll nr, ng, nb;
    cin >> nr >> ng >> nb;
    vector<ll> r(nr), g(ng), b(nb);
    for (ll i = (0); i < (nr); i++) cin >> r[i];
    for (ll i = (0); i < (ng); i++) cin >> g[i];
    for (ll i = (0); i < (nb); i++) cin >> b[i];
    sort(r.begin(), r.end());
    sort(g.begin(), g.end());
    sort(b.begin(), b.end());
    ll ans = INF;
    vector<lpair> lp;
    for (ll i = (0); i < (nr); i++) {
      lp.push_back({r[i], 0});
    }
    for (ll i = (0); i < (ng); i++) {
      lp.push_back({g[i], 1});
    }
    for (ll i = (0); i < (nb); i++) {
      lp.push_back({b[i], 2});
    }
    sort(lp.begin(), lp.end());
    vector<ll> pr, pg, pb;
    for (ll i = (0); i < (nr + ng + nb); i++) {
      if (lp[i].second == 0) {
        pr.push_back(i);
      } else if (lp[i].second == 1) {
        pg.push_back(i);
      } else {
        pb.push_back(i);
      }
    }
    for (ll i = (1); i < (nr + ng + nb - 1); i++) {
      if (lp[i].second == 0) {
        ll val_g = -1, val_b = -1;
        ll pos = lower_bound(pg.begin(), pg.end(), i) - pg.begin();
        if (pos != 0) {
          val_g = g[pos - 1];
        }
        pos = lower_bound(pb.begin(), pb.end(), i) - pb.begin();
        if (pos != nb) {
          val_b = b[pos];
        }
        if (val_g != -1 && val_b != -1) {
          ll val_r = lp[i].first;
          ll res = (val_r - val_g) * (val_r - val_g) +
                   (val_r - val_b) * (val_r - val_b) +
                   (val_b - val_g) * (val_b - val_g);
          ans = min(ans, res);
        }
        val_b = -1, val_g = -1;
        pos = lower_bound(pb.begin(), pb.end(), i) - pb.begin();
        if (pos != 0) {
          val_b = b[pos - 1];
        }
        pos = lower_bound(pg.begin(), pg.end(), i) - pg.begin();
        if (pos != ng) {
          val_g = g[pos];
        }
        if (val_g != -1 && val_b != -1) {
          ll val_r = lp[i].first;
          ll res = (val_r - val_g) * (val_r - val_g) +
                   (val_r - val_b) * (val_r - val_b) +
                   (val_b - val_g) * (val_b - val_g);
          ans = min(ans, res);
        }
      } else if (lp[i].second == 1) {
        ll val_r = -1, val_b = -1;
        ll pos = lower_bound(pr.begin(), pr.end(), i) - pr.begin();
        if (pos != 0) {
          val_r = r[pos - 1];
        }
        pos = lower_bound(pb.begin(), pb.end(), i) - pb.begin();
        if (pos != nb) {
          val_b = b[pos];
        }
        if (val_r != -1 && val_b != -1) {
          ll val_g = lp[i].first;
          ll res = (val_r - val_g) * (val_r - val_g) +
                   (val_r - val_b) * (val_r - val_b) +
                   (val_b - val_g) * (val_b - val_g);
          ans = min(ans, res);
        }
        val_r = -1, val_b = -1;
        pos = lower_bound(pb.begin(), pb.end(), i) - pb.begin();
        if (pos != 0) {
          val_b = b[pos - 1];
        }
        pos = lower_bound(pr.begin(), pr.end(), i) - pr.begin();
        if (pos != nr) {
          val_r = r[pos];
        }
        if (val_r != -1 && val_b != -1) {
          ll val_g = lp[i].first;
          ll res = (val_r - val_g) * (val_r - val_g) +
                   (val_r - val_b) * (val_r - val_b) +
                   (val_b - val_g) * (val_b - val_g);
          ans = min(ans, res);
        }
      } else {
        ll val_r = -1, val_g = -1;
        ll pos = lower_bound(pr.begin(), pr.end(), i) - pr.begin();
        if (pos != 0) {
          val_r = r[pos - 1];
        }
        pos = lower_bound(pg.begin(), pg.end(), i) - pg.begin();
        if (pos != ng) {
          val_g = g[pos];
        }
        if (val_r != -1 && val_g != -1) {
          ll val_b = lp[i].first;
          ll res = (val_r - val_g) * (val_r - val_g) +
                   (val_r - val_b) * (val_r - val_b) +
                   (val_b - val_g) * (val_b - val_g);
          ans = min(ans, res);
        }
        val_g = -1, val_r = -1;
        pos = lower_bound(pg.begin(), pg.end(), i) - pg.begin();
        if (pos != 0) {
          val_g = g[pos - 1];
        }
        pos = lower_bound(pr.begin(), pr.end(), i) - pr.begin();
        if (pos != nr) {
          val_r = r[pos];
        }
        if (val_r != -1 && val_g != -1) {
          ll val_b = lp[i].first;
          ll res = (val_r - val_g) * (val_r - val_g) +
                   (val_r - val_b) * (val_r - val_b) +
                   (val_b - val_g) * (val_b - val_g);
          ans = min(ans, res);
        }
      }
    }
    print(ans);
  }
}
