#include <bits/stdc++.h>
using namespace std;
int Gcd(int a, int b) {
  if (b == 0) return a;
  return Gcd(b, a % b);
}
int Lcm(int a, int b) { return a / Gcd(a, b) * b; }
inline long long read() {
  long long f = 1, x = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int maxn = 1e6 + 10;
long long a[maxn], b[maxn], c[maxn];
long long calc(long long x, long long y, long long z) {
  return (x - y) * (x - y) + (x - z) * (x - z) + (z - y) * (z - y);
}
int main() {
  int T = read();
  while (T--) {
    int na = read(), nb = read(), nc = read();
    for (int i = 1; i <= na; i++) {
      a[i] = read();
    }
    for (int i = 1; i <= nb; i++) {
      b[i] = read();
    }
    for (int i = 1; i <= nc; i++) {
      c[i] = read();
    }
    sort(a + 1, a + na + 1);
    sort(b + 1, b + nb + 1);
    sort(c + 1, c + nc + 1);
    long long ans = LLONG_MAX;
    for (int i = 1; i <= na; i++) {
      int x1 = lower_bound(b + 1, b + nb + 1, a[i]) - b;
      int x2 = lower_bound(c + 1, c + nc + 1, a[i]) - c;
      for (int j = max(1, x1 - 5); j <= min(nb, x1 + 5); j++) {
        for (int k = max(1, x2 - 5); k <= min(nc, x2 + 5); k++) {
          ans = min(ans, calc(a[i], b[j], c[k]));
        }
      }
    }
    for (int j = 1; j <= nb; j++) {
      int x1 = lower_bound(a + 1, a + na + 1, b[j]) - a;
      int x2 = lower_bound(c + 1, c + nc + 1, b[j]) - c;
      for (int i = max(1, x1 - 5); i <= min(na, x1 + 5); i++) {
        for (int k = max(1, x2 - 5); k <= min(nc, x2 + 5); k++) {
          ans = min(ans, calc(a[i], b[j], c[k]));
        }
      }
    }
    for (int k = 1; k <= nc; k++) {
      int x1 = lower_bound(a + 1, a + na + 1, c[k]) - a;
      int x2 = lower_bound(b + 1, b + nb + 1, c[k]) - b;
      for (int i = max(1, x1 - 5); i <= min(na, x1 + 5); i++) {
        for (int j = max(1, x2 - 5); j <= min(nb, x2 + 5); j++) {
          ans = min(ans, calc(a[i], b[j], c[k]));
        }
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
