#include <bits/stdc++.h>
#pragma GCC optimize("-O2")
using namespace std;
const int N = 2e5 + 5, MOD = 1e9 + 7;
const long double EPS = 1e-9;
long long dis(long long x, long long y, long long z) {
  return ((x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x));
}
long long val(vector<long long> x, vector<long long> y, vector<long long> z) {
  int xs = x.size();
  int ys = y.size();
  int zs = z.size();
  long long ans = LLONG_MAX;
  for (int i = 0; i < xs; i++) {
    auto ity = lower_bound(y.begin(), y.end(), x[i]);
    if (ity == y.end()) continue;
    long long y1 = y[ity - y.begin()];
    auto itz = upper_bound(z.begin(), z.end(), y1);
    if (itz == z.begin()) continue;
    long long z1 = z[itz - z.begin() - 1];
    long long x1 = x[i];
    ans = min(ans, dis(x1, y1, z1));
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int nr, ng, nb;
    cin >> nr >> ng >> nb;
    vector<long long> r(nr), g(ng), b(nb);
    for (int i = 0; i < nr; ++i) cin >> r[i];
    for (int i = 0; i < ng; ++i) cin >> g[i];
    for (int i = 0; i < nb; ++i) cin >> b[i];
    sort(r.begin(), r.end());
    sort(g.begin(), g.end());
    sort(b.begin(), b.end());
    long long ans = LLONG_MAX;
    ans = min(ans, val(r, g, b));
    ans = min(ans, val(r, b, g));
    ans = min(ans, val(b, r, g));
    ans = min(ans, val(b, g, r));
    ans = min(ans, val(g, r, b));
    ans = min(ans, val(g, b, r));
    cout << ans;
    cout << '\n';
  }
  return 0;
}
