#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long solve(vector<long long> &x, vector<long long> &y,
                vector<long long> &z) {
  long long mini = LLONG_MAX;
  long long nr = x.size(), ng = y.size(), nb = z.size();
  for (long long i = 0; i < nr; i++) {
    long long low = 0, high = ng - 1;
    long long mid, a = ng - 1;
    vector<long long> v1;
    while (low <= high) {
      mid = low + (high - low) / 2;
      if (y[mid] >= x[i]) {
        a = mid;
        high = mid - 1;
      } else {
        low = mid + 1;
      }
    }
    if (a != ng - 1) {
      v1.push_back(a + 1);
    }
    if (a != 0) {
      v1.push_back(a - 1);
    }
    v1.push_back(a);
    for (auto &j : v1) {
      vector<long long> v2;
      low = 0, high = nb - 1;
      long long b = nb - 1;
      while (low <= high) {
        mid = low + (high - low) / 2;
        if (z[mid] > (x[i] + y[j]) / 2) {
          b = mid;
          high = mid - 1;
        } else {
          low = mid + 1;
        }
      }
      if (b != nb - 1) {
        v2.push_back(b + 1);
      }
      if (b != 0) {
        v2.push_back(b - 1);
      }
      v2.push_back(b);
      for (auto &k : v2) {
        long long tmp = ((x[i] - y[j]) * (x[i] - y[j])) +
                        ((x[i] - z[k]) * (x[i] - z[k])) +
                        ((z[k] - y[j]) * (z[k] - y[j]));
        mini = min(mini, tmp);
      }
    }
  }
  return mini;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long nr, ng, nb;
    cin >> nr >> ng >> nb;
    vector<long long> x(nr), y(ng), z(nb);
    for (long long i = 0; i < nr; i++) {
      cin >> x[i];
    }
    for (long long i = 0; i < ng; i++) {
      cin >> y[i];
    }
    for (long long i = 0; i < nb; i++) {
      cin >> z[i];
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    sort(z.begin(), z.end());
    long long ans = LLONG_MAX;
    ans = min(ans, solve(x, y, z));
    ans = min(ans, solve(x, z, y));
    ans = min(ans, solve(y, x, z));
    ans = min(ans, solve(y, z, x));
    ans = min(ans, solve(z, x, y));
    ans = min(ans, solve(z, y, x));
    cout << ans << "\n";
    ;
  }
}
