#include <bits/stdc++.h>
using namespace std;
const int LM = 1e5 + 4;
int a, b, c;
int A[LM], B[LM], C[LM];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d%d", &a, &b, &c);
    for (int i = 1; i <= a; i++) scanf("%d", A + i);
    sort(A + 1, A + a + 1);
    for (int i = 1; i <= b; i++) scanf("%d", B + i);
    sort(B + 1, B + b + 1);
    for (int i = 1; i <= c; i++) scanf("%d", C + i);
    sort(C + 1, C + c + 1);
    vector<int> tmp;
    for (int i = 1; i <= a; i++) tmp.push_back(A[i]);
    for (int i = 1; i <= b; i++) tmp.push_back(B[i]);
    for (int i = 1; i <= c; i++) tmp.push_back(C[i]);
    sort(tmp.begin(), tmp.end());
    tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
    long long ans = 3e18;
    for (int K : tmp) {
      auto it1 = lower_bound(A + 1, A + a + 1, K);
      if (it1 == A + a + 1) it1--;
      auto it2 = lower_bound(B + 1, B + b + 1, K);
      if (it2 == B + b + 1) it2--;
      auto it3 = lower_bound(C + 1, C + c + 1, K);
      if (it3 == C + c + 1) it3--;
      for (auto Q = it1 - 1; Q <= it1 + 1; Q++) {
        if (A + 1 <= Q && Q <= A + a)
          for (auto X = it2 - 1; X <= it2 + 1; X++) {
            if (B + 1 <= X && X <= B + b)
              for (auto Y = it3 - 1; Y <= it3 + 1; Y++) {
                if (C + 1 <= Y && Y <= C + c) {
                  int p = *X, q = *Y, r = *Q;
                  long long cand = 1LL * (p - q) * (p - q) +
                                   1LL * (p - r) * (p - r) +
                                   1LL * (q - r) * (q - r);
                  ans = min(ans, cand);
                }
              }
          }
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
