#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
const long long maxn = 100005;
long long inf = 2000000009;
long long c[maxn], a[maxn], b[maxn];
long long f(long long x, long long y, long long z) {
  return (x - y) * (x - y) + (x - z) * (x - z) + (y - z) * (y - z);
}
signed main() {
  fast();
  long long t, i, j, k, n, m, p;
  cin >> t;
  while (t--) {
    cin >> n >> m >> p;
    for (i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (i = 0; i < m; i++) {
      cin >> b[i];
    }
    for (i = 0; i < p; i++) {
      cin >> c[i];
    }
    sort(a, a + n);
    sort(b, b + m);
    sort(c, c + p);
    a[n] = inf;
    b[m] = inf;
    c[p] = inf;
    long long ans = 7000000000000000018;
    long long x, y, z;
    for (i = 0; i < n; i++) {
      x = a[i];
      y = upper_bound(b, b + m + 1, x) - b - 1;
      z = lower_bound(c, c + p + 1, x) - c;
      if (y >= 0 && z < p) {
        y = b[y], z = c[z];
        ans = min(ans, f(x, y, z));
      }
      y = lower_bound(b, b + m + 1, x) - b;
      z = upper_bound(c, c + p + 1, x) - c - 1;
      if (y < m && z >= 0) {
        y = b[y], z = c[z];
        ans = min(ans, f(x, y, z));
      }
    }
    for (i = 0; i < m; i++) {
      x = b[i];
      y = upper_bound(a, a + n + 1, x) - a - 1;
      z = lower_bound(c, c + p + 1, x) - c;
      if (y >= 0 && z < p) {
        y = a[y], z = c[z];
        ans = min(ans, f(x, y, z));
      }
      y = lower_bound(a, a + n + 1, x) - a;
      z = upper_bound(c, c + p + 1, x) - c - 1;
      if (y < n && z >= 0) {
        y = a[y], z = c[z];
        ans = min(ans, f(x, y, z));
      }
    }
    for (i = 0; i < p; i++) {
      x = c[i];
      y = upper_bound(b, b + m + 1, x) - b - 1;
      z = lower_bound(a, a + n + 1, x) - a;
      if (y >= 0 && z < n) {
        y = b[y], z = a[z];
        ans = min(ans, f(x, y, z));
      }
      y = lower_bound(b, b + m + 1, x) - b;
      z = upper_bound(a, a + n + 1, x) - a - 1;
      if (y < m && z >= 0) {
        y = b[y], z = a[z];
        ans = min(ans, f(x, y, z));
      }
    }
    cout << ans << endl;
  }
}
