#include <bits/stdc++.h>
using namespace std;
long long res;
long long sq(long long x) { return x * 1ll * x; }
void calc(vector<long long> &a, vector<long long> &b, vector<long long> &c) {
  for (auto y : b) {
    auto x = lower_bound((a).begin(), (a).end(), y);
    auto z = upper_bound((c).begin(), (c).end(), y);
    if (x == a.end() || z == c.begin()) continue;
    z--;
    res = min(res, sq(*x - y) + sq(y - *z) + sq(*z - *x));
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long t;
  cin >> t;
  while (t--) {
    long long rdn, grn, bln;
    cin >> rdn >> grn >> bln;
    vector<long long> r(rdn), g(grn), b(bln);
    for (long long i = 0; i < rdn; cin >> r[i++])
      ;
    sort((r).begin(), (r).end());
    for (long long i = 0; i < grn; cin >> g[i++])
      ;
    sort((g).begin(), (g).end());
    for (long long i = 0; i < bln; cin >> b[i++])
      ;
    sort((b).begin(), (b).end());
    res = LLONG_MAX;
    calc(r, g, b);
    calc(r, b, g);
    calc(g, b, r);
    calc(g, r, b);
    calc(b, r, g);
    calc(b, g, r);
    cout << res << '\n';
  }
  return 0;
}
