#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9 + 9;
const long long inf = 2ll * 1e18;
const int max6 = 1e6 + 6;
const int modx = 1e9 + 123;
const int mody = 997;
const int base = 137;
int n[4];
int a[max6], b[max6], c[max6];
long long calc(int first, int second, int z) {
  long long res = 0;
  res = 1ll * (first - second) * (first - second) +
        1ll * (second - z) * (second - z) + 1ll * (z - first) * (z - first);
  return res;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int nr, nb, ng;
    cin >> nr >> nb >> ng;
    for (int i = 1; i <= nr; ++i) cin >> a[i];
    for (int i = 1; i <= nb; ++i) cin >> b[i];
    for (int i = 1; i <= ng; ++i) cin >> c[i];
    sort(a + 1, a + nr + 1);
    sort(b + 1, b + nb + 1);
    sort(c + 1, c + ng + 1);
    long long res = inf;
    for (int i = 1; i <= nr; ++i) {
      int u = lower_bound(b + 1, b + nb + 1, a[i]) - b;
      int v = lower_bound(c + 1, c + ng + 1, a[i]) - c;
      for (int j = max(1, u - 1); j <= min(u, nb); ++j)
        for (int k = max(1, v - 1); k <= min(v, ng); ++k)
          res = min(res, calc(a[i], b[j], c[k]));
    }
    for (int i = 1; i <= nb; ++i) {
      int u = lower_bound(a + 1, a + nr + 1, b[i]) - a;
      int v = lower_bound(c + 1, c + ng + 1, b[i]) - c;
      for (int j = max(1, u - 1); j <= min(u, nr); ++j)
        for (int k = max(1, v - 1); k <= min(v, ng); ++k)
          res = min(res, calc(b[i], a[j], c[k]));
    }
    for (int i = 1; i <= ng; ++i) {
      int u = lower_bound(a + 1, a + nr + 1, c[i]) - a;
      int v = lower_bound(b + 1, b + nb + 1, c[i]) - b;
      for (int j = max(1, u - 1); j <= min(u, nr); ++j)
        for (int k = max(1, v - 1); k <= min(v, nb); ++k)
          res = min(res, calc(c[i], a[j], b[k]));
    }
    cout << res << "\n";
  }
}
