#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 300005;
int n1, n2, n3;
int a[N], b[N], c[N];
ll sq(ll x) { return x * x; }
pair<int, int> v[N];
int nx[N][3];
int pv[N][3];
void solve() {
  for (int i = 0; i < n1; i++) {
    v[i] = {a[i], 0};
  }
  for (int i = 0; i < n2; i++) {
    v[n1 + i] = {b[i], 1};
  }
  for (int i = 0; i < n3; i++) {
    v[n1 + n2 + i] = {c[i], 2};
  }
  int n = n1 + n2 + n3;
  sort(v, v + n);
  ll ans = 4e18;
  nx[n][0] = nx[n][1] = nx[n][2] = n;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < 3; j++) nx[i][j] = nx[i + 1][j];
    nx[i][v[i].second] = i;
  }
  pv[0][0] = pv[0][1] = pv[0][2] = -1;
  pv[0][v[0].second] = 0;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 3; j++) pv[i][j] = pv[i - 1][j];
    pv[i][v[i].second] = i;
  }
  for (int i = 0; i < n; i++) {
    int me = v[i].second;
    int va = 0;
    while (va == me) va++;
    int vb = 0;
    while (vb == me or vb == va) vb++;
    for (int www = 0; www < 2; www++, swap(va, vb)) {
      int j = pv[i][va], k = nx[i][vb];
      if (j < 0 or k >= n) continue;
      ll cand = 0;
      cand += sq(v[i].first - v[j].first);
      cand += sq(v[i].first - v[k].first);
      cand += sq(v[k].first - v[j].first);
      ans = min(ans, cand);
    }
  }
  printf("%lld\n", ans);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d %d", &n1, &n2, &n3);
    for (int i = 0; i < n1; i++) scanf("%d", a + i);
    for (int i = 0; i < n2; i++) scanf("%d", b + i);
    for (int i = 0; i < n3; i++) scanf("%d", c + i);
    sort(a, a + n1);
    sort(b, b + n2);
    sort(c, c + n3);
    solve();
  }
}
