#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int maxn = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const double esp_0 = 1e-6;
const long long _INF = 2e18 + 10;
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
long long f(long long x, long long y, long long z) {
  return (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x);
}
long long b[maxn], g[maxn], r[maxn];
int main() {
  long long t;
  scanf("%lld", &t);
  while (t--) {
    long long nr, ng, nb;
    scanf("%lld%lld%lld", &nr, &ng, &nb);
    for (long long i = 0; i < nr; ++i) {
      scanf("%lld", &r[i]);
    }
    for (long long i = 0; i < ng; ++i) {
      scanf("%lld", &g[i]);
    }
    for (long long i = 0; i < nb; ++i) {
      scanf("%lld", &b[i]);
    }
    sort(r, r + nr);
    sort(g, g + ng);
    sort(b, b + nb);
    long long ans = _INF;
    for (long long i = 0; i < nr; ++i) {
      long long pos_y = lower_bound(g, g + ng, r[i]) - g;
      long long pos_z = lower_bound(b, b + nb, r[i]) - b;
      if (pos_y == ng) pos_y--;
      if (pos_z == nb) pos_z--;
      if (pos_y > 0) ans = min(ans, f(r[i], g[pos_y - 1], b[pos_z]));
      if (pos_z > 0) ans = min(ans, f(r[i], g[pos_y], b[pos_z - 1]));
      ans = min(ans, f(r[i], g[pos_y], b[pos_z]));
    }
    for (long long i = 0; i < ng; ++i) {
      long long pos_x = lower_bound(r, r + nr, g[i]) - r;
      long long pos_z = lower_bound(b, b + nb, g[i]) - b;
      if (pos_x == nr) pos_x--;
      if (pos_z == nb) pos_z--;
      if (pos_x > 0) ans = min(ans, f(r[pos_x - 1], g[i], b[pos_z]));
      if (pos_z > 0) ans = min(ans, f(r[pos_x], g[i], b[pos_z - 1]));
      ans = min(ans, f(r[pos_x], g[i], b[pos_z]));
    }
    for (long long i = 0; i < nb; ++i) {
      long long pos_y = lower_bound(g, g + ng, b[i]) - g;
      long long pos_x = lower_bound(r, r + nr, b[i]) - r;
      if (pos_y == ng) pos_y--;
      if (pos_x == nr) pos_x--;
      if (pos_y > 0) ans = min(ans, f(r[pos_x], g[pos_y - 1], b[i]));
      if (pos_x > 0) ans = min(ans, f(r[pos_x - 1], g[pos_y], b[i]));
      ans = min(ans, f(r[pos_x], g[pos_y], b[i]));
    }
    printf("%lld\n", ans);
  }
  return 0;
}
