#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
long long a[N], b[N], c[N];
long long cal(long long i, long long j) {
  long long v = (j - i) * (j - i);
  return v;
}
signed main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n1, n2, n3;
    cin >> n1 >> n2 >> n3;
    for (long long i = 0; i < n1; i++) {
      cin >> a[i];
    }
    for (long long i = 0; i < n2; i++) {
      cin >> b[i];
    }
    for (long long i = 0; i < n3; i++) {
      cin >> c[i];
    }
    sort(a, a + n1);
    sort(b, b + n2);
    sort(c, c + n3);
    a[n1] = 3000000000000000007LL;
    b[n2] = 3000000000000000007LL;
    c[n3] = 3000000000000000007LL;
    long long ans = 1;
    for (long long i = 0; i < 62; i++) {
      ans *= 2LL;
    }
    long long i = 0, j = 0, k = 0;
    while (i < n1 && j < n2 && k < n3) {
      long long val = cal(a[i], b[j]) + cal(b[j], c[k]) + cal(a[i], c[k]);
      ans = min(ans, val);
      long long v1 = 3000000000000000007LL, v2 = 3000000000000000007LL,
                v3 = 3000000000000000007LL;
      if (i + 1 < n1) {
        v1 = cal(a[i + 1], b[j]) + cal(b[j], c[k]) + cal(a[i + 1], c[k]);
      }
      if (j + 1 < n2) {
        v2 = cal(a[i], b[j + 1]) + cal(b[j + 1], c[k]) + cal(a[i], c[k]);
      }
      if (k + 1 < n3) {
        v3 = cal(a[i], b[j]) + cal(b[j], c[k + 1]) + cal(a[i], c[k + 1]);
      }
      if (v1 <= v2 && v1 <= v3) {
        i++;
      } else if (v2 <= v1 && v2 <= v3) {
        j++;
      } else if (v3 <= v1 && v3 <= v1) {
        k++;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
