#include <bits/stdc++.h>
using namespace std;
long long mod = (1000000007LL);
inline long long Mod(long long a, long long b) { return (a % b); }
inline long long poww(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
long long gcd(long long a, long long b) {
  while (b) {
    a %= b, swap(a, b);
  }
  return a;
}
void read(vector<long long> &w, long long n) {
  w.resize(n);
  for (long long i = 0; i < n; i++) cin >> w[i];
}
void print(vector<long long> &w) {
  for (long long i = 0; i < (long long)(w).size(); i++) {
    if (i == (long long)(w).size() - 1)
      cout << w[i] << "\n";
    else
      cout << w[i] << " ";
  }
}
long long n, m, q, k, v[300050], ans;
pair<long long, long long> w[300050];
string second;
long long F(long long x, long long y, long long z) {
  return (x - y) * (x - y) + (x - z) * (x - z) + (y - z) * (y - z);
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> q;
  while (q--) {
    long long ra, rb, rc;
    cin >> ra >> rb >> rc;
    vector<long long> A(ra), B(rb), C(rc);
    read(A, ra);
    read(B, rb);
    read(C, rc);
    sort(begin(A), end(A)), sort(begin(B), end(B)), sort(begin(C), end(C));
    A.erase(unique(begin(A), end(A)), A.end());
    B.erase(unique(begin(B), end(B)), B.end());
    C.erase(unique(begin(C), end(C)), C.end());
    ra = (long long)(A).size(), rb = (long long)(B).size(),
    rc = (long long)(C).size();
    long long ans = (long long)(4e18);
    for (long long i = 0; i < ra; i++) {
      long long l = lower_bound(begin(B), end(B), A[i]) - B.begin();
      long long r = lower_bound(begin(C), end(C), A[i]) - C.begin();
      long long li = max(0LL, l - 10), lii = min(rb - 1, l + 10);
      long long ri = max(0LL, r - 10), rii = min(rc - 1, r + 10);
      for (long long a = li; a <= lii; a++) {
        for (long long b = ri; b <= rii; b++) {
          ans = min(ans, F(A[i], B[a], C[b]));
        }
      }
    }
    for (long long i = 0; i < rb; i++) {
      long long l = lower_bound(begin(A), end(A), B[i]) - A.begin();
      long long r = lower_bound(begin(C), end(C), B[i]) - C.begin();
      long long li = max(0LL, l - 10), lii = min(ra - 1, l + 10);
      long long ri = max(0LL, r - 10), rii = min(rc - 1, r + 10);
      for (long long a = li; a <= lii; a++) {
        for (long long b = ri; b <= rii; b++) {
          ans = min(ans, F(B[i], A[a], C[b]));
        }
      }
    }
    for (long long i = 0; i < rc; i++) {
      long long l = lower_bound(begin(B), end(B), C[i]) - B.begin();
      long long r = lower_bound(begin(A), end(A), C[i]) - A.begin();
      long long li = max(0LL, l - 10), lii = min(rb - 1, l + 10);
      long long ri = max(0LL, r - 10), rii = min(ra - 1, r + 10);
      for (long long a = li; a <= lii; a++) {
        for (long long b = ri; b <= rii; b++) {
          ans = min(ans, F(C[i], B[a], A[b]));
        }
      }
    }
    cout << ans << "\n";
  }
}
