#include <bits/stdc++.h>
using namespace std;
long long ans;
void call(vector<long long> a, vector<long long> b, vector<long long> c) {
  long long i, x, y, xx;
  for (i = 0; i < b.size(); i++) {
    auto lower = lower_bound(a.begin(), a.end(), b[i]);
    auto upper = upper_bound(c.begin(), c.end(), b[i]);
    if (lower == a.end() || upper == c.begin()) {
    } else {
      upper--;
      x = *lower;
      y = *upper;
      xx = ((x - b[i]) * (x - b[i])) + ((y - b[i]) * (y - b[i])) +
           ((x - y) * (x - y));
      ans = min(ans, xx);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long i, a, b, c, x;
    ans = 9e18;
    vector<long long> v1, v2, v3;
    cin >> a >> b >> c;
    for (i = 0; i < a; i++) {
      cin >> x;
      v1.push_back(x);
    }
    for (i = 0; i < b; i++) {
      cin >> x;
      v2.push_back(x);
    }
    for (i = 0; i < c; i++) {
      cin >> x;
      v3.push_back(x);
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    sort(v3.begin(), v3.end());
    call(v1, v2, v3);
    call(v1, v3, v2);
    call(v2, v1, v3);
    call(v2, v3, v1);
    call(v3, v1, v2);
    call(v3, v2, v1);
    cout << ans << endl;
  }
}
