#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
long long int solve(long long int a, long long int b, long long int c) {
  long long int x =
      ((a - b) * (a - b)) + ((b - c) * (b - c)) + ((c - a) * (c - a));
  return x;
}
long long int get(long long int a[], long long int b[], long long int c[],
                  long long int nr, long long int ng, long long int nb) {
  long long int ans = 9e18, i, j, k;
  for (i = 0; i < ng; i++) {
    long long int x = lower_bound(a, a + nr, b[i]) - a,
                  y = lower_bound(c, c + nb, b[i]) - c;
    if (x == nr) x--;
    if (y == nb) y--;
    long long int x1 = x, y1 = y;
    if (x > 0) x1--;
    if (y > 0) y1--;
    long long int a1[2] = {a[x], a[x1]}, a2[2] = {c[y], c[y1]};
    for (j = 0; j < 2; j++) {
      for (k = 0; k < 2; k++) {
        ans = min(ans, solve(a1[j], b[i], a2[k]));
      }
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--) {
    long long int nr, ng, nb, i;
    cin >> nr >> ng >> nb;
    long long int a[nr], b[ng], c[nb];
    for (i = 0; i < nr; i++) cin >> a[i];
    for (i = 0; i < ng; i++) cin >> b[i];
    for (i = 0; i < nb; i++) cin >> c[i];
    sort(a, a + nr);
    sort(b, b + ng);
    sort(c, c + nb);
    long long int ans = 9e18;
    ans = min(ans, get(a, b, c, nr, ng, nb));
    ans = min(ans, get(a, c, b, nr, nb, ng));
    ans = min(ans, get(c, b, a, nb, ng, nr));
    ans = min(ans, get(b, a, c, ng, nr, nb));
    ans = min(ans, get(c, a, b, nb, nr, ng));
    ans = min(ans, get(b, c, a, ng, nb, nr));
    cout << ans << "\n";
  }
  return 0;
}
