#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long bestOfTwo(long long a, long long b, long long val) {
  return (abs(val - a) < abs(val - b)) ? a : b;
}
long long closest(vector<long long> &v, long long val) {
  if (val <= v[0]) return v[0];
  if (val >= v[v.size() - 1]) return v[v.size() - 1];
  long long low = 0, high = v.size() - 1, mid;
  while (low < high) {
    mid = (low + high) / 2LL;
    if (v[mid] == val) return v[mid];
    if (val < v[mid]) {
      if (mid && val > v[mid - 1]) return bestOfTwo(v[mid], v[mid - 1], val);
      high = mid;
    } else {
      if (mid + 1 < v.size() && val < v[mid + 1])
        return bestOfTwo(v[mid], v[mid + 1], val);
      low = mid + 1;
    }
  }
  return v[mid];
}
long long val(long long x, long long y, long long z) {
  return (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x);
}
int main() {
  long long t, nr, nb, ng, i, x, y, z, ans;
  cin >> t;
  while (t--) {
    cin >> nr >> ng >> nb;
    vector<long long> r, b, g;
    for (i = 0; i < nr; i++) {
      cin >> x;
      r.push_back(x);
    }
    for (i = 0; i < ng; i++) {
      cin >> x;
      g.push_back(x);
    }
    for (i = 0; i < nb; i++) {
      cin >> x;
      b.push_back(x);
    }
    sort(r.begin(), r.end());
    sort(g.begin(), g.end());
    sort(b.begin(), b.end());
    ans = LLONG_MAX;
    for (i = 0; i < nr; i++) {
      x = r[i];
      y = closest(g, x);
      z = closest(b, x);
      ans = min(ans, val(x, y, z));
    }
    for (i = 0; i < ng; i++) {
      y = g[i];
      x = closest(r, y);
      z = closest(b, y);
      ans = min(ans, val(x, y, z));
    }
    for (i = 0; i < nb; i++) {
      z = b[i];
      y = closest(g, z);
      x = closest(r, z);
      ans = min(ans, val(x, y, z));
    }
    cout << ans << endl;
  }
  return 0;
}
