#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
long long MOD = 998244353;
long long exp(long long n, long long e) {
  if (e == 0) return 1;
  long long temp = exp((n * n) % MOD, e / 2);
  return e % 2 == 0 ? temp : (temp * n) % MOD;
}
long long inverse(long long n) { return exp(n, MOD - 2); }
void frac(long long p, long long q) {
  cout << (p * inverse(q)) % MOD << endl;
  ;
}
long long LIM = 2e5 + 100;
vector<vector<long long> > adj(LIM);
vector<pair<long long, long long> > level;
vector<long long> S(LIM);
void dfs(long long n, long long par, long long d) {
  S[n] = 1;
  for (long long i = 0; i < ((long long)(adj[n]).size()); i++) {
    long long c = adj[n][i];
    if (c == par) continue;
    dfs(c, n, d + 1);
    S[n] += S[c];
  }
  level.push_back(pair<long long, long long>(d - S[n] + 1, n));
}
long long sq(long long n) { return n * n; }
void solve() {
  int a, b, c;
  cin >> a >> b >> c;
  vector<vector<long long> > x(3);
  x[0] = vector<long long>(a);
  x[1] = vector<long long>(b);
  x[2] = vector<long long>(c);
  for (int i = 0; i < a; i++) cin >> x[0][i];
  for (int i = 0; i < b; i++) cin >> x[1][i];
  for (int i = 0; i < c; i++) cin >> x[2][i];
  for (int i = 0; i < 3; i++) sort((x[i]).begin(), (x[i]).end());
  long long ans = 4e18;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (i == j) continue;
      int l = 3 - i - j;
      for (int k = 0; k < ((long long)(x[i]).size()); k++) {
        int j1 =
            lower_bound((x[j]).begin(), (x[j]).end(), x[i][k]) - x[j].begin();
        if (j1 == ((long long)(x[j]).size())) continue;
        int j2 =
            lower_bound((x[l]).begin(), (x[l]).end(), x[j][j1]) - x[l].begin();
        if (j2 == ((long long)(x[l]).size())) continue;
        long long temp = sq(x[i][k] - x[l][j2]);
        long long a = x[i][k];
        long long b = x[l][j2];
        int j3 = upper_bound((x[j]).begin(), (x[j]).end(),
                             (x[i][k] + x[l][j2]) / 2) -
                 x[j].begin();
        for (int m = j3 - 2; m <= j3 + 1; m++) {
          if (m < 0 || m >= ((long long)(x[j]).size())) continue;
          long long c = x[j][m];
          long long temp2 = temp + sq(a - c) + sq(b - c);
          ans = min(ans, temp2);
        }
      }
    }
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  vector<long long> a = {1, 2, 3, 4};
  int j = lower_bound(a.begin(), a.end(), 5) - a.begin();
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
