#include <bits/stdc++.h>
using namespace std;
const long long M = 1e6 + 7;
long long solve(vector<long long> a, vector<long long> b, vector<long long> c) {
  long long n = a.size(), m = b.size(), l = c.size();
  long long ans = (a[0] - b[0]) * (a[0] - b[0]) +
                  (c[0] - b[0]) * (c[0] - b[0]) + (a[0] - c[0]) * (a[0] - c[0]);
  for (long long i = 0; i < n; i++) {
    long long x = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
    for (long long j = min(x - 3, m); j <= min(x + 3, m); j++) {
      if (j < 0 || j > m) continue;
      long long y = lower_bound(c.begin(), c.end(), b[j]) - c.begin();
      for (long long k = min(y - 3, l); k <= min(y + 3, l); k++) {
        if ((i >= 0 && i < n) && (j >= 0 && j < m) && (k >= 0 && k < l)) {
          long long sum = (a[i] - b[j]) * (a[i] - b[j]) +
                          (c[k] - b[j]) * (c[k] - b[j]) +
                          (a[i] - c[k]) * (a[i] - c[k]);
          ans = min(ans, sum);
        }
      }
    }
  }
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long tt;
  cin >> tt;
  while (tt--) {
    long long n, m, l;
    cin >> n >> m >> l;
    vector<long long> a, b, c;
    for (long long i = 0; i < n; i++) {
      long long x;
      cin >> x;
      a.push_back(x);
    }
    for (long long i = 0; i < m; i++) {
      long long x;
      cin >> x;
      b.push_back(x);
    }
    for (long long i = 0; i < l; i++) {
      long long x;
      cin >> x;
      c.push_back(x);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    long long ans = (a[0] - b[0]) * (a[0] - b[0]) +
                    (c[0] - b[0]) * (c[0] - b[0]) +
                    (a[0] - c[0]) * (a[0] - c[0]);
    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, a, b));
    ans = min(ans, solve(c, b, a));
    cout << ans << "\n";
  }
  return 0;
}
