#include <bits/stdc++.h>
using namespace std;
const long long maxn = 100000 + 10;
long long T, n, m, k, a[maxn], b[maxn], c[maxn];
long long solve(long long a[], long long b[], long long c[], long long len1,
                long long len2, long long len3) {
  long long opt1 = 1, opt3 = 1, minn = 3 * 1e18, x, y, z;
  for (int i = 1; i <= len2; i++) {
    y = b[i];
    while (opt1 <= len1 - 1 && a[opt1 + 1] <= b[i]) {
      opt1++;
    }
    x = a[opt1];
    while (opt3 <= len3 - 1 && c[opt3] < b[i]) {
      opt3++;
    }
    z = c[opt3];
    long long ans = (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x);
    minn = min(minn, ans);
  }
  return minn;
}
int main() {
  cin >> T;
  while (T--) {
    cin >> n >> m >> k;
    for (long long i = 1; i <= n; i++) cin >> a[i];
    for (long long i = 1; i <= m; i++) cin >> b[i];
    for (long long i = 1; i <= k; i++) cin >> c[i];
    sort(a + 1, a + 1 + n);
    sort(b + 1, b + 1 + m);
    sort(c + 1, c + 1 + k);
    long long minn = 3 * 1e18;
    minn = min(minn, solve(a, b, c, n, m, k));
    minn = min(minn, solve(a, c, b, n, k, m));
    minn = min(minn, solve(b, a, c, m, n, k));
    minn = min(minn, solve(b, c, a, m, k, n));
    minn = min(minn, solve(c, a, b, k, n, m));
    minn = min(minn, solve(c, b, a, k, m, n));
    cout << minn << endl;
  }
  return 0;
}
