#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count() +
            'd' + 'o' + 'i' + 'n' + 'g' + 'g' + 'e' + 'y');
const long long inf = 4e18;
const long double eps = 1e-6;
const long long mc = 200;
long double start_time;
long long ans;
long long get(long long a, long long b, long long c) {
  return a * a + b * b + c * c;
}
void relax(vector<long long>& a, vector<long long>& b, vector<long long>& c) {
  for (long long x : a) {
    auto ity = upper_bound(b.begin(), b.end(), x);
    if (ity == b.begin()) continue;
    auto itz = lower_bound(c.begin(), c.end(), x);
    if (itz == c.end()) continue;
    long long y = *(--ity), z = *itz;
    ans = min(ans, get(x - y, x - z, y - z));
  }
}
void solve() {
  long long na, nb, nc;
  cin >> na >> nb >> nc;
  vector<long long> v1(na), v2(nb), v3(nc);
  for (long long i = 0; i < na; ++i) cin >> v1[i];
  for (long long i = 0; i < nb; ++i) cin >> v2[i];
  for (long long i = 0; i < nc; ++i) cin >> v3[i];
  sort(v1.begin(), v1.end()), sort(v2.begin(), v2.end()),
      sort(v3.begin(), v3.end());
  ans = inf;
  relax(v1, v2, v3);
  relax(v1, v3, v2);
  relax(v2, v1, v3);
  relax(v2, v3, v1);
  relax(v3, v1, v2);
  relax(v3, v2, v1);
  cout << ans << "\n";
}
signed main() {
  start_time = clock();
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  long long q;
  cin >> q;
  for (long long i = 0; i < q; ++i) solve();
  return 0;
}
