#include <bits/stdc++.h>
using namespace std;
long long sq(int x) { return 1ll * x * x; }
void solve(std::vector<int> r, std::vector<int> g, std::vector<int> b,
           long long& ans) {
  for (auto x : r) {
    auto y = lower_bound(g.begin(), g.end(), x);
    auto z = upper_bound(b.begin(), b.end(), x);
    if (y == g.end() || z == b.begin()) continue;
    z--;
    ans = min(ans, sq(x - *y) + sq(*y - *z) + sq(x - *z));
  }
}
int main() {
  ios::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    int nr, ng, nb;
    cin >> nr >> ng >> nb;
    std::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());
    long long ans = 9e18;
    solve(r, g, b, ans);
    solve(r, b, g, ans);
    solve(g, b, r, ans);
    solve(g, r, b, ans);
    solve(b, r, g, ans);
    solve(b, g, r, ans);
    cout << ans << endl;
  }
  return 0;
}
