#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = INT_MAX;
const long long MAX_N = 1e6 + 7;
long long ans = 9e18;
long long sq(int a, int b) { return 1LL * (a - b) * (a - b); }
void comp(vector<int> a, vector<int> b, vector<int> c) {
  for (auto x : b) {
    auto itr1 = lower_bound((a).begin(), (a).end(), x);
    auto itr2 = upper_bound((c).begin(), (c).end(), x);
    if (itr1 == a.end() || itr2 == c.begin()) continue;
    itr2--;
    ans = min(ans, sq(*itr1, x) + sq(*itr2, x) + sq(*itr1, *itr2));
  }
}
void solve() {
  ans = 9e18;
  int nr, ng, nb;
  cin >> nr >> ng >> nb;
  vector<int> 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());
  comp(r, g, b);
  comp(b, g, r);
  comp(b, r, g);
  comp(g, r, b);
  comp(g, b, r);
  comp(r, b, g);
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) solve();
}
