#include <bits/stdc++.h>
using namespace std;
long long po(long long x) { return x * x; };
long long sq(long long a, long long b, long long c) {
  return po(a - b) + po(a - c) + po(c - b);
};
long long res = LLONG_MAX;
void hlp(vector<long long>& ar, vector<long long>& br, vector<long long>& cr) {
  long long ans;
  for (long long i : br) {
    auto x = upper_bound(ar.begin(), ar.end(), i);
    auto y = lower_bound(cr.begin(), cr.end(), i);
    if (x == ar.begin() || y == cr.end()) continue;
    x--;
    ans = sq(*x, *y, i);
    if (ans < res) res = ans;
  };
  return;
}
void sol() {
  res = LLONG_MAX;
  int na, nb, nc;
  cin >> na >> nb >> nc;
  vector<long long> ar(na);
  vector<long long> br(nb);
  vector<long long> cr(nc);
  for (int i = 0; i < na; ++i) scanf("%lld", &ar[i]);
  for (int i = 0; i < nb; ++i) scanf("%lld", &br[i]);
  for (int i = 0; i < nc; ++i) scanf("%lld", &cr[i]);
  sort(ar.begin(), ar.end());
  sort(br.begin(), br.end());
  sort(cr.begin(), cr.end());
  hlp(ar, br, cr);
  hlp(br, ar, cr);
  hlp(ar, cr, br);
  hlp(br, cr, ar);
  hlp(cr, ar, br);
  hlp(cr, br, ar);
  cout << res << endl;
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    sol();
  }
  return 0;
}
