#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long a[N], b[N], c[N];
long long ans = LLONG_MAX;
int m, n, k;
long long solve(long long a[], long long b[], long long c[], long long m,
                long long n, long long k) {
  ans = LLONG_MAX;
  for (int i = 0; i < n; ++i) {
    auto fi = lower_bound(a, a + m, b[i]);
    auto se = lower_bound(c, c + k, b[i]);
    long long temp;
    long long temp1;
    for (int g = 0; g < 2; ++g) {
      for (int j = 0; j < 2; ++j) {
        if (g == 0 && fi == (a + m) || j == 0 && se == (c + k) ||
            g == 1 && fi == a || j == 1 && se == c) {
          continue;
        }
        temp = *(fi - g);
        temp1 = *(se - j);
        long long gg = (temp - b[i]) * (temp - b[i]) +
                       (temp1 - b[i]) * (temp1 - b[i]) +
                       (temp - temp1) * (temp - temp1);
        if (gg < 0) continue;
        ans = min(ans, gg);
      }
    }
  }
  return ans;
}
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  int _;
  cin >> _;
  while (_--) {
    cin >> m >> n >> k;
    ans = LLONG_MAX;
    for (int i = 0; i < m; ++i) {
      cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
      cin >> b[i];
    }
    for (int i = 0; i < k; ++i) {
      cin >> c[i];
    }
    a[m] = b[n] = c[k] = 0;
    sort(a, a + m);
    sort(b, b + n);
    sort(c, c + k);
    ans = min(min(solve(a, b, c, m, n, k), solve(a, c, b, m, k, n)),
              solve(b, a, c, n, m, k));
    cout << ans << endl;
  }
  return 0;
}
