#include <bits/stdc++.h>
using namespace std;
long long cal(long long a, long long b, long long c) {
  return (a - b) * (a - b) + (b - c) * (b - c) + (a - c) * (a - c);
}
long long fun(vector<long long> a, vector<long long> b, vector<long long> c) {
  long long ans = cal(a[0], b[0], c[0]);
  int n1 = a.size();
  int n2 = b.size();
  int n3 = c.size();
  for (int i = 0; i < n1; i++) {
    vector<long long> b1;
    vector<long long> c1;
    int ind = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
    if (ind != n2) {
      b1.push_back(b[ind]);
      long long req = (a[i] + b[ind]) / 2;
      int ind2 = lower_bound(c.begin(), c.end(), req) - c.begin();
      if (ind2 != n3) {
        c1.push_back(c[ind2]);
      }
      if (ind2) c1.push_back(c[ind2 - 1]);
    }
    if (ind) {
      b1.push_back(b[ind - 1]);
      long long req = (a[i] + b[ind - 1]) / 2;
      int ind2 = lower_bound(c.begin(), c.end(), req) - c.begin();
      if (ind2 != n3) {
        c1.push_back(c[ind2]);
      }
      if (ind2) c1.push_back(c[ind2 - 1]);
    }
    for (int j = 0; j < (int)b1.size(); j++) {
      for (int k = 0; k < (int)c1.size(); k++)
        ans = min(ans, cal(a[i], b1[j], c1[k]));
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n1, n2, n3;
    cin >> n1 >> n2 >> n3;
    long long ans = 0;
    vector<long long> a(n1, 0);
    vector<long long> b(n2, 0);
    vector<long long> c(n3, 0);
    for (int i = 0; i < n1; i++) cin >> a[i];
    for (int i = 0; i < n2; i++) cin >> b[i];
    for (int i = 0; i < n3; i++) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    ans = fun(a, b, c);
    ans = min(ans, fun(a, c, b));
    ans = min(ans, fun(b, a, c));
    ans = min(ans, fun(b, c, a));
    ans = min(ans, fun(c, a, b));
    ans = min(ans, fun(c, b, a));
    cout << ans << endl;
  }
  return 0;
}
