#include <bits/stdc++.h>
using namespace std;
long long Floor(long long v[], long long &key, long long &n) {
  long long r = n, l = 0;
  long long m;
  if (key < v[0]) return -1;
  while (r - l > 1) {
    m = l + (r - l) / 2;
    if (v[m] <= key)
      l = m;
    else
      r = m;
  }
  return l;
}
void solve(long long b[], long long a[], long long c[], long long &g,
           long long &r, long long &bl, long long &sum) {
  for (long long i = 0; i < g; ++i) {
    long long pos1 = lower_bound(a, a + r, b[i]) - a;
    long long pos2 = lower_bound(c, c + bl, b[i]) - c;
    long long pos3 = Floor(a, b[i], r);
    long long pos4 = Floor(c, b[i], bl);
    if (pos1 == r) pos1 = r - 1;
    if (pos2 == bl) pos2 = bl - 1;
    if (pos3 == -1) pos3 = 0;
    if (pos4 == -1) pos4 = 0;
    long long s1 = (b[i] - a[pos1]) * (b[i] - a[pos1]) +
                   (c[pos2] - a[pos1]) * (c[pos2] - a[pos1]) +
                   (b[i] - c[pos2]) * (b[i] - c[pos2]);
    long long s2 = (b[i] - a[pos1]) * (b[i] - a[pos1]) +
                   (c[pos4] - a[pos1]) * (c[pos4] - a[pos1]) +
                   (b[i] - c[pos4]) * (b[i] - c[pos4]);
    long long s3 = (b[i] - a[pos3]) * (b[i] - a[pos3]) +
                   (c[pos2] - a[pos3]) * (c[pos2] - a[pos3]) +
                   (b[i] - c[pos2]) * (b[i] - c[pos2]);
    long long s4 = (b[i] - a[pos3]) * (b[i] - a[pos3]) +
                   (c[pos4] - a[pos3]) * (c[pos4] - a[pos3]) +
                   (b[i] - c[pos4]) * (b[i] - c[pos4]);
    sum = min({sum, s1, s2, s3, s4});
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long r, g, bl;
    cin >> r >> g >> bl;
    long long a[r], b[g], c[bl];
    long long sum = 5e18;
    for (long long i = 0; i < r; ++i) cin >> a[i];
    for (long long i = 0; i < g; ++i) cin >> b[i];
    for (long long i = 0; i < bl; ++i) cin >> c[i];
    sort(a, a + r);
    sort(b, b + g);
    sort(c, c + bl);
    solve(b, a, c, g, r, bl, sum);
    solve(a, b, c, r, g, bl, sum);
    solve(c, a, b, bl, r, g, sum);
    solve(a, c, b, r, bl, g, sum);
    solve(b, c, a, g, bl, r, sum);
    solve(c, b, a, bl, g, r, sum);
    cout << sum << endl;
  }
}
