#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int nr, ng, nb;
    cin >> nr >> ng >> nb;
    vector<int> R, G, B;
    for (int i = 0; i < nr; i++) {
      int r;
      cin >> r;
      R.push_back(r);
    }
    sort(R.begin(), R.end());
    for (int i = 0; i < ng; i++) {
      int g;
      cin >> g;
      G.push_back(g);
    }
    sort(G.begin(), G.end());
    for (int i = 0; i < nb; i++) {
      int b;
      cin >> b;
      B.push_back(b);
    }
    sort(B.begin(), B.end());
    vector<vector<int>> gems = {R, G, B};
    vector<int> ns = {nr, ng, nb};
    ll ans = 3e18;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < ns[i]; j++) {
        for (int bump = 1; bump >= -1; bump -= 2) {
          int cur = gems[i][j];
          auto k1 = upper_bound(gems[(i + bump + 3) % 3].begin(),
                                gems[(i + bump + 3) % 3].end(), cur) -
                    gems[(i + bump + 3) % 3].begin() - 1;
          auto k2 = lower_bound(gems[(i - bump + 3) % 3].begin(),
                                gems[(i - bump + 3) % 3].end(), cur) -
                    gems[(i - bump + 3) % 3].begin();
          if (k1 < 0 || k2 >= int(gems[(i - bump + 3) % 3].size())) continue;
          ll x = gems[(i + bump + 3) % 3][k1];
          ll y = gems[(i - bump + 3) % 3][k2];
          ll z = cur;
          ans = min(ans,
                    (x - y) * (x - y) + (x - z) * (x - z) + (y - z) * (y - z));
        }
      }
    }
    cout << ans << "\n";
  }
}
