#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const int mod = 1e9 + 7;
long long ans, x[maxn], y[maxn], z[maxn];
void solve(long long a, long long b, long long c, long long* x, long long* y,
           long long* z) {
  for (int i = 1; i < b + 1; ++i) {
    if (x[1] > y[i] || z[c] < y[i]) continue;
    long long p1 = upper_bound(x + 1, x + a + 1, y[i]) - x - 1;
    long long p2 = lower_bound(z + 1, z + c + 1, y[i]) - z;
    ans = min(ans, (x[p1] - y[i]) * (x[p1] - y[i]) +
                       (z[p2] - y[i]) * (z[p2] - y[i]) +
                       (x[p1] - z[p2]) * (x[p1] - z[p2]));
  }
}
int qaq() {
  long long a, b, c;
  ans = 1ll << 61;
  scanf("%lld", &a), scanf("%lld", &b), scanf("%lld", &c);
  for (int i = 1; i < a + 1; ++i) scanf("%lld", &x[i]);
  for (int i = 1; i < b + 1; ++i) scanf("%lld", &y[i]);
  for (int i = 1; i < c + 1; ++i) scanf("%lld", &z[i]);
  sort(x + 1, x + a + 1);
  sort(y + 1, y + b + 1);
  sort(z + 1, z + c + 1);
  solve(a, b, c, x, y, z);
  solve(a, c, b, x, z, y);
  solve(b, a, c, y, x, z);
  solve(b, c, a, y, z, x);
  solve(c, a, b, z, x, y);
  solve(c, b, a, z, y, x);
  return printf("%lld\n", ans);
}
int main() {
  int _;
  scanf("%d", &_);
  while (_--) qaq();
}
