#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> wt(3);
long long a[3];
long long check1(long long x, long long nxtInd) {
  long long l = 0, r = a[nxtInd] - 1;
  long long i = nxtInd;
  long long ans = -1;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (wt[i][mid] > x)
      r = mid - 1;
    else {
      ans = wt[i][mid];
      l = mid + 1;
    }
  }
  return ans;
}
long long check2(long long x, long long nxtInd) {
  auto it = lower_bound(wt[nxtInd].begin(), wt[nxtInd].end(), x);
  if (it == wt[nxtInd].end()) return -1;
  return *it;
}
long long fun(long long a, long long b, long long c) {
  long long s1 = (a - b) * (a - b);
  long long s2 = (b - c) * (b - c);
  long long s3 = (c - a) * (c - a);
  return s1 + s2 + s3;
}
signed main() {
  std ::ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    cin >> a[0] >> a[1] >> a[2];
    for (long long i = 0; i < 3; i++) {
      wt[i] = vector<long long>(a[i]);
      for (long long j = 0; j < a[i]; j++) cin >> wt[i][j];
      sort((wt[i]).begin(), (wt[i]).end());
    }
    long long best = 5e18;
    for (long long i = 0; i < 3; i++) {
      for (long long j = 0; j < a[i]; j++) {
        long long p0 = check1(wt[i][j], (i + 2) % 3);
        long long p1 = wt[i][j];
        long long p2 = check2(wt[i][j], (i + 1) % 3);
        if (p0 != -1 && p2 != -1) best = min(best, fun(p0, p1, p2));
        p0 = check1(wt[i][j], (i + 1) % 3);
        p1 = wt[i][j];
        p2 = check2(wt[i][j], (i + 2) % 3);
        if (p0 != -1 && p2 != -1) best = min(best, fun(p0, p1, p2));
        p0 = wt[i][j];
        p1 = check2(wt[i][j], (i + 1) % 3);
        p2 = check2(wt[i][j], (i + 2) % 3);
        if (p1 != -1 && p2 != -1) best = min(best, fun(p0, p1, p2));
      }
    }
    cout << best << '\n';
  }
}
