#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
ll sqr(ll x) { return x * x; }
ll calc(const vector<int> &a, const vector<int> &b, const vector<int> &c) {
  ll ans = numeric_limits<ll>::max();
  for (auto x : a) {
    vector<int> ys, zs;
    auto pos = lower_bound(b.begin(), b.end(), x);
    if (pos != b.end()) ys.push_back(*pos);
    if (pos != b.begin()) ys.push_back(*(pos - 1));
    pos = lower_bound(c.begin(), c.end(), x);
    if (pos != c.end()) zs.push_back(*pos);
    if (pos != c.begin()) zs.push_back(*(pos - 1));
    for (auto y : ys) {
      for (auto z : zs) {
        ll cur = sqr(x - y) + sqr(x - z) + sqr(y - z);
        ans = min(ans, cur);
      }
    }
  }
  return ans;
}
void solve() {
  int nr, ng, nb;
  scanf("%d%d%d", &nr, &ng, &nb);
  vector<int> r(nr), g(ng), b(nb);
  for (int i = 0; i < nr; ++i) scanf("%d", &r[i]);
  for (int i = 0; i < ng; ++i) scanf("%d", &g[i]);
  for (int i = 0; i < nb; ++i) scanf("%d", &b[i]);
  sort(r.begin(), r.end());
  sort(g.begin(), g.end());
  sort(b.begin(), b.end());
  ll ans = min({calc(r, g, b), calc(g, r, b), calc(b, r, g)});
  printf("%lld\n", ans);
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
}
