#include <bits/stdc++.h>
using namespace std;
long long F(int x, int y, int z) {
  return 1LL * (x - y) * (x - y) + 1LL * (x - z) * (x - z) +
         1LL * (y - z) * (y - z);
}
long long f(int x[], int na, int y[], int nb, int z[], int nc) {
  long long r = LLONG_MAX;
  for (int k = 0; k < na; ++k) {
    int i, j;
    i = upper_bound(y, y + nb, x[k]) - y - 1;
    if (i >= 0) {
      j = lower_bound(z, z + nc, x[k]) - z;
      if (j < nc) r = min(r, F(x[k], y[i], z[j]));
    }
    i = upper_bound(z, z + nc, x[k]) - z - 1;
    if (i >= 0) {
      j = lower_bound(y, y + nb, x[k]) - y;
      if (j < nb) r = min(r, F(x[k], y[j], z[i]));
    }
  }
  return r;
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  const int N = 1e5;
  int t, x[N], y[N], z[N];
  cin >> t;
  while (t--) {
    int na, nb, nc;
    cin >> na >> nb >> nc;
    for (int i = 0; i < na; ++i) cin >> x[i];
    for (int i = 0; i < nb; ++i) cin >> y[i];
    for (int i = 0; i < nc; ++i) cin >> z[i];
    sort(x, x + na);
    sort(y, y + nb);
    sort(z, z + nc);
    cout << min(f(x, na, y, nb, z, nc),
                min(f(y, nb, x, na, z, nc), f(z, nc, x, na, y, nb)))
         << '\n';
  }
  return 0;
}
