#include <bits/stdc++.h>
using namespace std;
int Nr, Ng, Nb;
const int MAXN = 1e5 + 15;
long long R[MAXN], G[MAXN], B[MAXN];
long long P2(long long a) { return a * a; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    cin >> Nr >> Ng >> Nb;
    for (int i = 0; i < Nr; ++i) cin >> R[i];
    for (int i = 0; i < Ng; ++i) cin >> G[i];
    for (int i = 0; i < Nb; ++i) cin >> B[i];
    sort(R, R + Nr);
    sort(G, G + Ng);
    sort(B, B + Nb);
    long long ans = 0x7FFFFFFFFFFFFFFF;
    for (int i = 0; i < Nr; ++i) {
      int idx1, idx2;
      idx1 = lower_bound(G, G + Ng, R[i]) - G - 1;
      if (idx1 >= 0) {
        idx2 = lower_bound(B, B + Nb, (R[i] + G[idx1]) / 2) - B - 1;
        if (idx2 >= 0)
          ans = min(ans, P2(R[i] - G[idx1]) + P2(G[idx1] - B[idx2]) +
                             P2(B[idx2] - R[i]));
        idx2++;
        if (idx2 < Nb)
          ans = min(ans, P2(R[i] - G[idx1]) + P2(G[idx1] - B[idx2]) +
                             P2(B[idx2] - R[i]));
      }
      idx1++;
      if (idx1 < Ng) {
        idx2 = lower_bound(B, B + Nb, (R[i] + G[idx1]) / 2) - B - 1;
        if (idx2 >= 0)
          ans = min(ans, P2(R[i] - G[idx1]) + P2(G[idx1] - B[idx2]) +
                             P2(B[idx2] - R[i]));
        idx2++;
        if (idx2 < Nb)
          ans = min(ans, P2(R[i] - G[idx1]) + P2(G[idx1] - B[idx2]) +
                             P2(B[idx2] - R[i]));
      }
    }
    for (int i = 0; i < Ng; ++i) {
      int idx1, idx2;
      idx1 = lower_bound(B, B + Nb, G[i]) - B - 1;
      if (idx1 >= 0) {
        idx2 = lower_bound(R, R + Nr, (G[i] + B[idx1]) / 2) - R - 1;
        if (idx2 >= 0)
          ans = min(ans, P2(R[idx2] - G[i]) + P2(G[i] - B[idx1]) +
                             P2(B[idx1] - R[idx2]));
        idx2++;
        if (idx2 < Nr)
          ans = min(ans, P2(R[idx2] - G[i]) + P2(G[i] - B[idx1]) +
                             P2(B[idx1] - R[idx2]));
      }
      idx1++;
      if (idx1 < Nb) {
        idx2 = lower_bound(R, R + Nr, (G[i] + B[idx1]) / 2) - R - 1;
        if (idx2 >= 0)
          ans = min(ans, P2(R[idx2] - G[i]) + P2(G[i] - B[idx1]) +
                             P2(B[idx1] - R[idx2]));
        idx2++;
        if (idx2 < Nr)
          ans = min(ans, P2(R[idx2] - G[i]) + P2(G[i] - B[idx1]) +
                             P2(B[idx1] - R[idx2]));
      }
    }
    for (int i = 0; i < Nb; ++i) {
      int idx1, idx2;
      idx1 = lower_bound(R, R + Nr, B[i]) - R - 1;
      if (idx1 >= 0) {
        idx2 = lower_bound(G, G + Ng, (B[i] + R[idx1]) / 2) - G - 1;
        if (idx2 >= 0)
          ans = min(ans, P2(R[idx1] - G[idx2]) + P2(G[idx2] - B[i]) +
                             P2(B[i] - R[idx1]));
        idx2++;
        if (idx2 < Ng)
          ans = min(ans, P2(R[idx1] - G[idx2]) + P2(G[idx2] - B[i]) +
                             P2(B[i] - R[idx1]));
      }
      idx1++;
      if (idx1 < Nr) {
        idx2 = lower_bound(G, G + Ng, (B[i] + R[idx1]) / 2) - G - 1;
        if (idx2 >= 0)
          ans = min(ans, P2(R[idx1] - G[idx2]) + P2(G[idx2] - B[i]) +
                             P2(B[i] - R[idx1]));
        idx2++;
        if (idx2 < Ng)
          ans = min(ans, P2(R[idx1] - G[idx2]) + P2(G[idx2] - B[i]) +
                             P2(B[i] - R[idx1]));
      }
    }
    cout << ans << endl;
  }
  return 0;
}
