#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
long long solve(vector<long long> &A, vector<long long> &B,
                vector<long long> &C) {
  long long ans = 9e18;
  int a = A.size(), b = B.size(), c = C.size();
  long long a_, a__, b_, b__;
  for (int i = 0; i < a; i++) {
    long long a_ = -1, a__ = -1, b_ = -1, b__ = -1;
    int low = 0, high = b - 1;
    while (low <= high) {
      int mid = (high + low) / 2;
      if (B[mid] <= A[i]) {
        a_ = B[mid];
        low = mid + 1;
      } else {
        high = mid - 1;
      }
    }
    low = 0;
    high = c - 1;
    while (low <= high) {
      int mid = (high + low) / 2;
      if (C[mid] <= A[i]) {
        b_ = C[mid];
        low = mid + 1;
      } else {
        high = mid - 1;
      }
    }
    low = 0;
    high = b - 1;
    while (low <= high) {
      int mid = (high + low) / 2;
      if (B[mid] <= A[i]) {
        low = mid + 1;
      } else {
        a__ = B[mid];
        high = mid - 1;
      }
    }
    low = 0;
    high = c - 1;
    while (low <= high) {
      int mid = (high + low) / 2;
      if (C[mid] <= A[i]) {
        low = mid + 1;
      } else {
        b__ = C[mid];
        high = mid - 1;
      }
    }
    if (b_ == -1) {
      b_ = b__;
    }
    if (b__ == -1) {
      b__ = b_;
    }
    if (a__ == -1) {
      a__ = a_;
    }
    if (a_ == -1) {
      a_ = a__;
    }
    ans = min({ans,
               (A[i] - a_) * (A[i] - a_) + (A[i] - b_) * (A[i] - b_) +
                   (b_ - a_) * (b_ - a_),
               (A[i] - a__) * (A[i] - a__) + (A[i] - b__) * (A[i] - b__) +
                   (b__ - a__) * (b__ - a__),
               (A[i] - a_) * (A[i] - a_) + (A[i] - b__) * (A[i] - b__) +
                   (b__ - a_) * (b__ - a_),
               (A[i] - a__) * (A[i] - a__) + (A[i] - b_) * (A[i] - b_) +
                   (b_ - a__) * (b_ - a__)});
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t, n, m, k, q, x, a, b, c, d;
  cin >> t;
  while (t--) {
    cin >> a >> b >> c;
    long long ans = 9e18;
    vector<long long> A(a), B(b), C(c);
    for (auto &it : A) {
      cin >> it;
    }
    for (auto &it : B) {
      cin >> it;
    }
    for (auto &it : C) {
      cin >> it;
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    ans = min(solve(A, B, C), ans);
    ans = min(solve(A, C, B), ans);
    ans = min(solve(B, C, A), ans);
    ans = min(solve(B, A, C), ans);
    ans = min(solve(C, A, B), ans);
    ans = min(solve(C, B, A), ans);
    cout << ans << "\n";
  }
}
