#include <bits/stdc++.h>
using namespace std;
long long vl(long long x, long long y, long long z) {
  return (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int nr, ng, nb;
    cin >> nr >> ng >> nb;
    vector<long long> 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];
    vector<vector<long long> > rgb{r, g, b};
    vector<set<int> > a{set<int>(r.begin(), r.end()),
                        set<int>(g.begin(), g.end()),
                        set<int>(b.begin(), b.end())};
    vector<long long> mx(3);
    vector<long long> mn(3);
    for (int i = 0; i < 3; i++) {
      mx[i] = *max_element(rgb[i].begin(), rgb[i].end());
      mn[i] = *min_element(rgb[i].begin(), rgb[i].end());
    }
    long long bv = 8e18;
    for (int i = 0; i < 3; i++) {
      for (long long x : rgb[i]) {
        if (x <= mx[(i + 1) % 3] && x >= mn[(i + 2) % 3]) {
          long long u = *a[(i + 1) % 3].lower_bound(x);
          long long l = *prev(a[(i + 2) % 3].upper_bound(x));
          bv = min(bv, vl(x, u, l));
        }
        if (x <= mx[(i + 2) % 3] && x >= mn[(i + 1) % 3]) {
          long long u = *a[(i + 2) % 3].lower_bound(x);
          long long l = *prev(a[(i + 1) % 3].upper_bound(x));
          bv = min(bv, vl(x, u, l));
        }
      }
    }
    cout << bv << '\n';
  }
}
