#include <bits/stdc++.h>
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
using namespace std;
using ll = long long;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
ll devc(ll x, ll y) { return (x + y - 1) / y; }
ll dist(ll x, ll y, ll z) {
  return (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x);
}
void solve(ll &ans, vector<ll> &a, vector<ll> &b, vector<ll> &c) {
  ll L = (ll)b.size();
  for (ll i = 0; i < (L); ++i) {
    ll y = b[i];
    auto itrx = upper_bound((a).begin(), (a).end(), y);
    if (itrx == a.begin()) continue;
    --itrx;
    auto itrz = lower_bound((c).begin(), (c).end(), y);
    if (itrz == c.end()) continue;
    ll x = *itrx, z = *itrz;
    chmin(ans, dist(x, y, z));
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
  ll t;
  cin >> t;
  for (ll _ = 0; _ < (t); ++_) {
    ll nr, ng, nb;
    cin >> nr >> ng >> nb;
    vector<ll> r(nr), g(ng), b(nb);
    for (ll i = 0; i < (nr); ++i) cin >> r[i];
    for (ll i = 0; i < (ng); ++i) cin >> g[i];
    for (ll i = 0; i < (nb); ++i) cin >> b[i];
    sort((r).begin(), (r).end()), sort((g).begin(), (g).end()),
        sort((b).begin(), (b).end());
    ll ans = 5e18;
    solve(ans, r, g, b);
    solve(ans, r, b, g);
    solve(ans, g, r, b);
    solve(ans, g, b, r);
    solve(ans, b, r, g);
    solve(ans, b, g, r);
    cout << (ans) << '\n';
  }
  return 0;
}
