#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long t, na, nb, nc, a[N], b[N], c[N], ans;
long long calc(long long x, long long y, long long z) {
  return (x - y) * (x - y) + (y - z) * (y - z) + (x - z) * (x - z);
}
void solve(long long a[N], long long b[N], long long c[N], long long na,
           long long nb, long long nc) {
  for (long long i = 1; i <= na; i++) {
    long long x = lower_bound(b + 1, b + 1 + nb, a[i]) - b,
              y = upper_bound(c + 1, c + 1 + nc, a[i]) - c - 1;
    if (x <= nb && y >= 1) ans = min(ans, calc(a[i], b[x], c[y]));
    x = upper_bound(b + 1, b + 1 + nb, a[i]) - b - 1,
    y = lower_bound(c + 1, c + 1 + nc, a[i]) - c;
    if (x >= 1 && y <= nc) ans = min(ans, calc(a[i], b[x], c[y]));
  }
}
signed main() {
  scanf("%lld", &t);
  while (t--) {
    scanf("%lld%lld%lld", &na, &nb, &nc), ans = 4e18;
    for (long long i = 1; i <= na; i++) scanf("%lld", &a[i]);
    for (long long i = 1; i <= nb; i++) scanf("%lld", &b[i]);
    for (long long i = 1; i <= nc; i++) scanf("%lld", &c[i]);
    sort(a + 1, a + 1 + na), sort(b + 1, b + 1 + nb), sort(c + 1, c + 1 + nc);
    solve(a, b, c, na, nb, nc), solve(b, a, c, nb, na, nc),
        solve(c, a, b, nc, na, nb);
    printf("%lld\n", ans);
  }
  return 0;
}
