#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long ans = LONG_LONG_MAX;
long long sq(int x) { return 1ll * x * x; }
void solver(vector<int> r, vector<int> g, vector<int> b) {
  for (auto j : r) {
    auto y = lower_bound(g.begin(), g.end(), j);
    auto z = upper_bound(b.begin(), b.end(), j);
    if (y == g.end() || z == b.begin()) {
      continue;
    }
    z--;
    ans = min(ans, sq(j - *y) + sq(*y - *z) + sq(*z - j));
  }
}
void solve() {
  int nr, ng, nb;
  cin >> nr >> ng >> nb;
  vector<int> r(nr), g(ng), b(nb);
  vector<pair<int, int>> v;
  for (int i = 0; i < nr; i++) {
    cin >> r[i];
    v.push_back(make_pair(r[i], 0));
  }
  for (int i = 0; i < ng; i++) {
    cin >> g[i];
    v.push_back(make_pair(g[i], 1));
  }
  for (int i = 0; i < nb; i++) {
    cin >> b[i];
    v.push_back(make_pair(b[i], 2));
  }
  sort(r.begin(), r.end());
  sort(b.begin(), b.end());
  sort(g.begin(), g.end());
  ans = LONG_LONG_MAX;
  solver(r, g, b);
  solver(r, b, g);
  solver(g, b, r);
  solver(g, r, b);
  solver(b, r, g);
  solver(b, g, r);
  cout << ans << endl;
  ans = LONG_LONG_MAX;
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
}
