#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long inf = 9e18;
long long nearest(vector<long long>& v, const long long& x) {
  long long pos = lower_bound(v.begin(), v.end(), x) - v.begin();
  if (pos == v.size()) {
    pos--;
  } else if (v[pos] != x && pos != 0) {
    if (v[pos] - x > x - v[pos - 1]) pos--;
  }
  return v[pos];
}
long long sol(vector<long long>& a, vector<long long>& b,
              vector<long long>& c) {
  long long ans = inf, j, k;
  for (auto& i : a) {
    j = nearest(b, i);
    k = nearest(c, (j + i) / 2);
    ans = min(ans, (i - j) * (i - j) + (j - k) * (j - k) + (k - i) * (k - i));
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long na, nb, nc;
    cin >> na >> nb >> nc;
    vector<vector<long long> > v = {
        vector<long long>(na), vector<long long>(nb), vector<long long>(nc)};
    for (auto& i : v) {
      for (auto& j : i) {
        cin >> j;
      }
      sort(i.begin(), i.end());
    }
    long long ans = inf;
    ans = min(ans, sol(v[0], v[1], v[2]));
    ans = min(ans, sol(v[1], v[2], v[0]));
    ans = min(ans, sol(v[2], v[0], v[1]));
    cout << ans << endl;
  }
}
