#include <bits/stdc++.h>
using namespace std;
long long n[3], x;
vector<long long> X[3];
long long sq(long long a) { return a * a; }
long long result(long long a, long long b, long long c) {
  return sq(a - b) + sq(b - c) + sq(a - c);
}
void solve() {
  for (int o = 0; o < 3; o++) cin >> n[o];
  for (int o = 0; o < 3; o++) {
    X[o].clear();
    for (int i = 0; i < n[o]; i++) {
      cin >> x;
      X[o].push_back(x);
    }
    sort(X[o].begin(), X[o].end());
  }
  vector<int> perm = {0, 1, 2};
  long long best = 8LL * (long long)1e18;
  do {
    long long beg = 0;
    long long en = 0;
    for (long long mid = 0; mid < X[perm[1]].size(); mid++) {
      while (beg + 1 < X[perm[0]].size() and
             X[perm[0]][beg + 1] <= X[perm[1]][mid])
        beg++;
      while (en + 1 < X[perm[2]].size() and X[perm[2]][en] < X[perm[1]][mid])
        en++;
      best =
          min(best, result(X[perm[0]][beg], X[perm[1]][mid], X[perm[2]][en]));
    }
  } while (next_permutation(perm.begin(), perm.end()));
  cout << best << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
