#include <bits/stdc++.h>
using namespace std;
long long int solve(vector<long long int> y, vector<long long int> x,
                    vector<long long int> z) {
  long long int res = LLONG_MAX;
  long long int n = ((int)(y).size());
  for (int i = 0; i < n; i++) {
    auto x1 = lower_bound(x.begin(), x.end(), y[i]);
    auto x2 = lower_bound(x.begin(), x.end(), y[i]);
    if (x1 == x.end()) {
      x1--;
    }
    if (x2 != x.begin()) {
      x2--;
    }
    auto z1 = lower_bound(z.begin(), z.end(), y[i]);
    auto z2 = lower_bound(z.begin(), z.end(), y[i]);
    if (z1 == z.end()) {
      z1--;
    }
    if (z2 != z.begin()) {
      z2--;
    }
    long long int a1 = (*x1) - y[i], b1 = (*z1) - y[i];
    long long int a2 = (*x2) - y[i], b2 = (*z2) - y[i];
    long long int a3 = (*x1) - y[i], b3 = (*z2) - y[i];
    long long int a4 = (*x2) - y[i], b4 = (*z1) - y[i];
    res = min(res, 2LL * ((a1 * a1) + (b1 * b1) - (a1 * b1)));
    res = min(res, 2LL * ((a2 * a2) + (b2 * b2) - (a2 * b2)));
    res = min(res, 2LL * ((a3 * a3) + (b3 * b3) - (a3 * b3)));
    res = min(res, 2LL * ((a4 * a4) + (b4 * b4) - (a4 * b4)));
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long int n1, n2, n3;
    cin >> n1 >> n2 >> n3;
    vector<long long int> r(n1), g(n2), b(n3);
    for (int i = 0; i < n1; i++) {
      cin >> r[i];
    }
    for (int i = 0; i < n2; i++) {
      cin >> g[i];
    }
    for (int i = 0; i < n3; i++) {
      cin >> b[i];
    }
    sort(r.begin(), r.end());
    sort(g.begin(), g.end());
    sort(b.begin(), b.end());
    long long int ans = solve(r, g, b);
    ans = min(ans, solve(r, b, g));
    ans = min(ans, solve(g, r, b));
    ans = min(ans, solve(g, b, r));
    ans = min(ans, solve(b, r, g));
    ans = min(ans, solve(b, g, r));
    cout << ans << "\n";
  }
  return 0;
}
