#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 17;
int Q;
int Al, Bl, Cl;
int A[maxn], B[maxn], C[maxn];
inline void read(int n, vector<int> &v) {
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v.push_back(x);
  }
}
long long first(long long x, long long y, long long z) {
  long long sum = 0;
  sum += 1LL * (x - y) * (x - y);
  sum += 1LL * (x - z) * (x - z);
  sum += 1LL * (y - z) * (y - z);
  return sum;
}
long long solve(vector<int> &x, vector<int> &y, vector<int> &z) {
  set<long long> ys, zs;
  for (int v : y) ys.insert(1LL * v);
  for (int v : z) zs.insert(2LL * v);
  long long ret = 1LL << 62;
  for (int i = 0; i < x.size(); i++) {
    long long xv = 1LL * x[i];
    auto xr = ys.lower_bound(xv);
    if (xr != ys.end()) {
      long long yv = 1LL * (*xr);
      auto xyr = zs.lower_bound(xv + yv);
      if (xyr != zs.end()) {
        long long zv = 1LL * (*xyr) / 2LL;
        ret = min(ret, first(xv, yv, zv));
      }
      auto xyl = zs.upper_bound(xv + yv);
      if (xyl != zs.begin()) {
        int zv = 1LL * (*prev(xyl)) / 2LL;
        ret = min(ret, first(xv, yv, zv));
      }
    }
    auto xl = ys.upper_bound(xv);
    if (xl != ys.begin()) {
      long long yv = 1LL * (*prev(xl));
      auto xyr = zs.lower_bound(xv + yv);
      if (xyr != zs.end()) {
        long long zv = 1LL * (*xyr) / 2LL;
        ret = min(ret, first(xv, yv, zv));
      }
      auto xyl = zs.upper_bound(xv + yv);
      if (xyl != zs.begin()) {
        int zv = 1LL * (*prev(xyl)) / 2LL;
        ret = min(ret, first(xv, yv, zv));
      }
    }
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> Q;
  while (Q--) {
    vector<int> A, B, C;
    cin >> Al >> Bl >> Cl;
    read(Al, A);
    read(Bl, B);
    read(Cl, C);
    long long ans = 1LL << 62;
    ans = min(ans, solve(A, B, C));
    ans = min(ans, solve(A, C, B));
    ans = min(ans, solve(B, C, A));
    ans = min(ans, solve(B, A, C));
    ans = min(ans, solve(C, A, B));
    ans = min(ans, solve(C, B, A));
    printf("%I64d\n", ans);
  }
  return 0;
}
