#include <bits/stdc++.h>
using namespace std;
long long call(vector<long long> &a, vector<long long> &b,
               vector<long long> &c) {
  long long ans = LLONG_MAX;
  long long na = a.size();
  for (int i = 0; i < na; i++) {
    long long num1 = -1000000000000, num2 = -1000000000000;
    auto it1 = lower_bound(b.begin(), b.end(), a[i]);
    if (it1 != b.end()) num1 = *it1;
    if (it1 != b.begin()) {
      it1--;
      num2 = *it1;
    }
    long long numb;
    if (abs(num1 - a[i]) < abs(num2 - a[i]))
      numb = num1;
    else
      numb = num2;
    num1 = -1000000000000, num2 = -1000000000000;
    it1 = lower_bound(c.begin(), c.end(), a[i]);
    if (it1 != c.end()) num1 = *it1;
    if (it1 != c.begin()) {
      it1--;
      num2 = *it1;
    }
    long long numc;
    if (abs(num1 - a[i]) < abs(num2 - a[i]))
      numc = num1;
    else
      numc = num2;
    long long numa = a[i];
    long long temp = (numb - numa) * (numb - numa) +
                     (numb - numc) * (numb - numc) +
                     (numa - numc) * (numa - numc);
    ans = min(ans, temp);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long na, nb, nc, i, j;
    cin >> na >> nb >> nc;
    vector<long long> a(na), b(nb), c(nc);
    for (i = 0; i < na; i++) cin >> a[i];
    for (i = 0; i < nb; i++) cin >> b[i];
    for (i = 0; i < nc; i++) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    long long temp1 = call(a, b, c);
    long long temp2 = call(b, a, c);
    long long temp3 = call(c, a, b);
    long long ans = min(temp1, min(temp2, temp3));
    cout << ans << "\n";
  }
}
