#include <bits/stdc++.h>
using namespace std;
long long solve(vector<long long> v1, vector<long long> v2,
                vector<long long> v3) {
  v1.push_back(1000000001);
  v2.push_back(1000000001);
  v3.push_back(1000000001);
  int p1 = 0, p2 = 0, p3 = 0;
  long long ANS = LLONG_MAX;
  for (int p1 = 0; p1 < v1.size() - 1; p1++) {
    while (v2[p2 + 1] <= v1[p1]) p2++;
    long long VAL = (v1[p1] - v2[p2]) * (v1[p1] - v2[p2]) +
                    (v1[p1] - v3[p3]) * (v1[p1] - v3[p3]) +
                    (v2[p2] - v3[p3]) * (v2[p2] - v3[p3]);
    while (v3[p3 + 1] <= v1[p1]) {
      if (VAL >= (v1[p1] - v2[p2]) * (v1[p1] - v2[p2]) +
                     (v1[p1] - v3[p3 + 1]) * (v1[p1] - v3[p3 + 1]) +
                     (v2[p2] - v3[p3 + 1]) * (v2[p2] - v3[p3 + 1])) {
        p3++;
        VAL = (v1[p1] - v2[p2]) * (v1[p1] - v2[p2]) +
              (v1[p1] - v3[p3]) * (v1[p1] - v3[p3]) +
              (v2[p2] - v3[p3]) * (v2[p2] - v3[p3]);
      } else
        break;
    }
    long long RES = (v1[p1] - v2[p2]) * (v1[p1] - v2[p2]) +
                    (v1[p1] - v3[p3]) * (v1[p1] - v3[p3]) +
                    (v2[p2] - v3[p3]) * (v2[p2] - v3[p3]);
    ANS = min(ANS, RES);
  }
  return ANS;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T;
  cin >> T;
  int per[6][3] = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2},
                   {1, 2, 0}, {2, 0, 1}, {2, 1, 0}};
  while (T--) {
    long long ans = LLONG_MAX;
    vector<long long> st[3];
    int a, b, c;
    cin >> a >> b >> c;
    for (int i = 0; i < a; i++) {
      long long val;
      cin >> val;
      st[0].push_back(val);
    }
    for (int i = 0; i < b; i++) {
      long long val;
      cin >> val;
      st[1].push_back(val);
    }
    for (int i = 0; i < c; i++) {
      long long val;
      cin >> val;
      st[2].push_back(val);
    }
    for (int i = 0; i < 3; i++) sort(st[i].begin(), st[i].end());
    for (int i = 0; i < 6; i++) {
      ans = min(ans, solve(st[per[i][0]], st[per[i][1]], st[per[i][2]]));
    }
    cout << ans << endl;
  }
}
