#include <bits/stdc++.h>
long long fpow(long long x, long long y, long long p = 1000000007) {
  x = x % p;
  long long sum = 1;
  while (y) {
    if (y & 1) sum = sum * x;
    sum %= p;
    y = y >> 1;
    x = x * x;
    x %= p;
  }
  return sum;
}
long long fact[1000007] = {0};
void facto() {
  fact[0] = 1;
  fact[1] = 1;
  for (long long i = 2; i < 100007; i++)
    fact[i] = (fact[i - 1] * i) % 1000000007;
}
long long ncr(long long n, long long r) {
  long long res = 1;
  res = fact[n];
  res = (res * (fpow(fact[r], 1000000007 - 2))) % 1000000007;
  res = (res * (fpow(fact[n - r], 1000000007 - 2))) % 1000000007;
  return res;
}
long long npr(long long n, long long r) {
  long long res = 1;
  res = fact[n];
  res = (res * (fpow(fact[n - r], 1000000007 - 2))) % 1000000007;
  return res;
}
long long modmul(long long x, long long y) { return (x * y) % 1000000007; }
long long modadd(long long x, long long y) { return (x + y) % 1000000007; }
long long modsub(long long x, long long y) {
  return (x - y + 1000000007) % 1000000007;
}
using namespace std;
long long ans;
long long sq(long long x) { return 1ll * x * x; }
void solve(vector<long long> a, vector<long long> b, vector<long long> c) {
  for (auto x : a) {
    auto y = lower_bound(b.begin(), b.end(), x);
    auto z = upper_bound(c.begin(), c.end(), x);
    if (y == b.end() || z == c.begin()) {
      continue;
    }
    z--;
    ans = min(ans, sq(x - *y) + sq(*y - *z) + sq(*z - x));
  }
}
void solv() {
  long long n1, n2, n3;
  cin >> n1 >> n2 >> n3;
  vector<long long> r(n1), g(n2), b(n3);
  for (long long i = 0; i < n1; i++) {
    cin >> r[i];
  }
  for (long long i = 0; i < n2; i++) {
    cin >> g[i];
  }
  for (long long i = 0; i < n3; i++) {
    cin >> b[i];
  }
  sort(r.begin(), r.end());
  sort(g.begin(), g.end());
  sort(b.begin(), b.end());
  ans = 2 * 1e18;
  solve(r, g, b);
  solve(r, b, g);
  solve(g, b, r);
  solve(g, r, b);
  solve(b, r, g);
  solve(b, g, r);
  cout << ans << endl;
}
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    solv();
  }
}
