#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int tt;
  cin >> tt;
  while (tt--) {
    int na, nb, nc;
    cin >> na >> nb >> nc;
    vector<int> a(na), b(nb), c(nc);
    for (int i = 0; i < na; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < nb; i++) {
      cin >> b[i];
    }
    for (int i = 0; i < nc; i++) {
      cin >> c[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    auto solve = [](vector<int> &a, vector<int> &b, vector<int> &c) {
      long long res = 4 * 1e18;
      for (auto i : b) {
        auto l = lower_bound(a.begin(), a.end(), i + 1);
        auto r = lower_bound(c.begin(), c.end(), i);
        if (l == a.begin() || r == c.end()) continue;
        long long x = *prev(l), y = i, z = *r;
        long long w = (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x);
        res = min(res, w);
      }
      return res;
    };
    long long ans = 4 * 1e18;
    ans = min(ans, solve(a, b, c));
    ans = min(ans, solve(a, c, b));
    ans = min(ans, solve(b, a, c));
    ans = min(ans, solve(b, c, a));
    ans = min(ans, solve(c, b, a));
    ans = min(ans, solve(c, a, b));
    cout << ans << '\n';
  }
  return 0;
}
