#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4e5 + 5;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
long long a[MAXN], b[MAXN], c[MAXN];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    a[0] = -1e9;
    b[0] = -1e9;
    c[0] = -1e9;
    for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
    for (int i = 1; i <= m; i++) scanf("%lld", &b[i]);
    for (int i = 1; i <= k; i++) scanf("%lld", &c[i]);
    sort(a + 1, a + 1 + n);
    sort(b + 1, b + 1 + m);
    sort(c + 1, c + 1 + k);
    long long ans = INF;
    for (int i = 1; i <= n; i++) {
      long long aa = a[i];
      long long b0 = lower_bound(b + 1, b + 1 + m, a[i]) - b;
      long long bb = b[b0];
      long long c0 = lower_bound(c + 1, c + 1 + k, a[i]) - c;
      long long cc = c[c0];
      long long tmp =
          (aa - bb) * (aa - bb) + (cc - bb) * (cc - bb) + (aa - cc) * (aa - cc);
      ans = min(ans, tmp);
      bb = b[b0 - 1];
      cc = c[c0 - 1];
      tmp =
          (aa - bb) * (aa - bb) + (cc - bb) * (cc - bb) + (aa - cc) * (aa - cc);
      ans = min(ans, tmp);
      bb = b[b0];
      cc = c[c0 - 1];
      tmp =
          (aa - bb) * (aa - bb) + (cc - bb) * (cc - bb) + (aa - cc) * (aa - cc);
      ans = min(ans, tmp);
      bb = b[b0 - 1];
      cc = c[c0];
      tmp =
          (aa - bb) * (aa - bb) + (cc - bb) * (cc - bb) + (aa - cc) * (aa - cc);
      ans = min(ans, tmp);
    }
    for (int i = 1; i <= m; i++) {
      long long bb = b[i];
      long long a0 = lower_bound(a + 1, a + 1 + n, b[i]) - a;
      long long aa = a[a0];
      long long c0 = lower_bound(c + 1, c + 1 + k, b[i]) - c;
      long long cc = c[c0];
      long long tmp =
          (aa - bb) * (aa - bb) + (cc - bb) * (cc - bb) + (aa - cc) * (aa - cc);
      ans = min(ans, tmp);
      aa = a[a0 - 1];
      cc = c[c0 - 1];
      tmp =
          (aa - bb) * (aa - bb) + (cc - bb) * (cc - bb) + (aa - cc) * (aa - cc);
      ans = min(ans, tmp);
      aa = a[a0];
      cc = c[c0 - 1];
      tmp =
          (aa - bb) * (aa - bb) + (cc - bb) * (cc - bb) + (aa - cc) * (aa - cc);
      ans = min(ans, tmp);
      aa = a[a0 - 1];
      cc = c[c0];
      tmp =
          (aa - bb) * (aa - bb) + (cc - bb) * (cc - bb) + (aa - cc) * (aa - cc);
      ans = min(ans, tmp);
    }
    for (int i = 1; i <= k; i++) {
      long long cc = c[i];
      long long b0 = lower_bound(b + 1, b + 1 + m, c[i]) - b;
      long long bb = b[b0];
      long long a0 = lower_bound(a + 1, a + 1 + n, c[i]) - a;
      long long aa = a[a0];
      long long tmp =
          (aa - bb) * (aa - bb) + (cc - bb) * (cc - bb) + (aa - cc) * (aa - cc);
      ans = min(ans, tmp);
      bb = b[b0 - 1];
      aa = a[a0 - 1];
      tmp =
          (aa - bb) * (aa - bb) + (cc - bb) * (cc - bb) + (aa - cc) * (aa - cc);
      bb = b[b0];
      aa = a[a0 - 1];
      tmp =
          (aa - bb) * (aa - bb) + (cc - bb) * (cc - bb) + (aa - cc) * (aa - cc);
      ans = min(ans, tmp);
      bb = b[b0 - 1];
      aa = a[a0];
      tmp =
          (aa - bb) * (aa - bb) + (cc - bb) * (cc - bb) + (aa - cc) * (aa - cc);
      ans = min(ans, tmp);
    }
    printf("%lld\n", ans);
    for (int i = 1; i <= n; i++) a[i] = 0;
    for (int i = 1; i <= m; i++) b[i] = 0;
    for (int i = 1; i <= k; i++) c[i] = 0;
  }
  return 0;
}
