#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int gcdExtended(long long int a, long long int b, long long int *x,
                          long long int *y) {
  if (a == 0) {
    *x = 0;
    *y = 1;
    return b;
  }
  long long int x1, y1;
  long long int gcd = gcdExtended(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
long long int mod = 1000000007;
long long int binpower(long long int a, long long int b) {
  long long int ans = 1;
  while (b > 0) {
    if (b & 1) ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}
bool isPrime(int n) {
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) return false;
  }
  return true;
}
int bits(long long int a) { return __builtin_popcount(a); }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int test = 1;
  cin >> test;
  while (test--) {
    int n[3];
    for (int i = 0; i < 3; ++i) cin >> n[i];
    vector<vector<long long int> > v(3);
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < n[i]; ++j) {
        long long int val;
        cin >> val;
        v[i].push_back(val);
      }
    }
    for (int i = 0; i < 3; ++i) sort(v[i].begin(), v[i].end());
    vector<int> perm;
    for (int i = 0; i < 3; ++i) perm.push_back(i);
    long long int ans = -1;
    do {
      int fi = perm[0], se = perm[1], th = perm[2];
      for (int i = 0; i < v[fi].size(); ++i) {
        long long int x = v[fi][i];
        if (v[se][0] > x) continue;
        long long int y = *(--upper_bound(v[se].begin(), v[se].end(), x));
        if (*(--v[th].end()) < x) break;
        long long int z = *(lower_bound(v[th].begin(), v[th].end(), x));
        long long int t =
            (x - y) * (x - y) + (x - z) * (x - z) + (z - y) * (z - y);
        if (ans == -1)
          ans = t;
        else
          ans = min(ans, t);
      }
    } while (next_permutation(perm.begin(), perm.end()));
    cout << ans << endl;
  }
  return 0;
}
