#include <bits/stdc++.h>
using namespace std;
void shikhar7s(long long int cas) {
  long long int nr, ng, nb;
  cin >> nr >> ng >> nb;
  vector<long long int> r, g, b;
  long long int i, a;
  for (i = 0; i < nr; i++) {
    cin >> a;
    r.push_back(a);
  }
  for (i = 0; i < ng; i++) {
    cin >> a;
    g.push_back(a);
  }
  for (i = 0; i < nb; i++) {
    cin >> a;
    b.push_back(a);
  }
  sort(r.begin(), r.end());
  sort(g.begin(), g.end());
  sort(b.begin(), b.end());
  long long int j, k, ans = 2000000000000000000;
  for (i = 0; i < nr; i++) {
    j = lower_bound(g.begin(), g.end(), r[i]) - g.begin();
    if (j >= ng) break;
    k = lower_bound(b.begin(), b.end(), g[j]) - b.begin();
    if (k >= nb) break;
    a = (r[i] + b[k]) / 2;
    j = lower_bound(g.begin(), g.end(), a) - g.begin();
    if (j < ng && g[j] <= b[k]) {
      ans = min(ans, ((r[i] - g[j]) * (r[i] - g[j])) +
                         ((b[k] - g[j]) * (b[k] - g[j])) +
                         ((r[i] - b[k]) * (r[i] - b[k])));
    }
    j--;
    if (j >= 0 && g[j] >= r[i]) {
      ans = min(ans, ((r[i] - g[j]) * (r[i] - g[j])) +
                         ((b[k] - g[j]) * (b[k] - g[j])) +
                         ((r[i] - b[k]) * (r[i] - b[k])));
    }
  }
  for (i = 0; i < nr; i++) {
    k = lower_bound(b.begin(), b.end(), r[i]) - b.begin();
    if (k >= nb) break;
    j = lower_bound(g.begin(), g.end(), b[k]) - g.begin();
    if (j >= ng) break;
    a = (r[i] + g[j]) / 2;
    k = lower_bound(b.begin(), b.end(), a) - b.begin();
    if (k < nb && b[k] <= g[j]) {
      ans = min(ans, ((r[i] - g[j]) * (r[i] - g[j])) +
                         ((b[k] - g[j]) * (b[k] - g[j])) +
                         ((r[i] - b[k]) * (r[i] - b[k])));
    }
    k--;
    if (k >= 0 && b[k] >= r[i]) {
      ans = min(ans, ((r[i] - g[j]) * (r[i] - g[j])) +
                         ((b[k] - g[j]) * (b[k] - g[j])) +
                         ((r[i] - b[k]) * (r[i] - b[k])));
    }
  }
  for (j = 0; j < ng; j++) {
    i = lower_bound(r.begin(), r.end(), g[j]) - r.begin();
    if (i >= nr) break;
    k = lower_bound(b.begin(), b.end(), r[i]) - b.begin();
    if (k >= nb) break;
    a = (g[j] + b[k]) / 2;
    i = lower_bound(r.begin(), r.end(), a) - r.begin();
    if (i < nr && r[i] <= b[k]) {
      ans = min(ans, ((r[i] - g[j]) * (r[i] - g[j])) +
                         ((b[k] - g[j]) * (b[k] - g[j])) +
                         ((r[i] - b[k]) * (r[i] - b[k])));
    }
    i--;
    if (i >= 0 && r[i] >= g[j]) {
      ans = min(ans, ((r[i] - g[j]) * (r[i] - g[j])) +
                         ((b[k] - g[j]) * (b[k] - g[j])) +
                         ((r[i] - b[k]) * (r[i] - b[k])));
    }
  }
  for (j = 0; j < ng; j++) {
    k = lower_bound(b.begin(), b.end(), g[j]) - b.begin();
    if (k >= nb) break;
    i = lower_bound(r.begin(), r.end(), b[k]) - r.begin();
    if (i >= nr) break;
    a = (r[i] + g[j]) / 2;
    k = lower_bound(b.begin(), b.end(), a) - b.begin();
    if (k < nb && b[k] <= r[i]) {
      ans = min(ans, ((r[i] - g[j]) * (r[i] - g[j])) +
                         ((b[k] - g[j]) * (b[k] - g[j])) +
                         ((r[i] - b[k]) * (r[i] - b[k])));
    }
    k--;
    if (k >= 0 && b[k] >= g[j]) {
      ans = min(ans, ((r[i] - g[j]) * (r[i] - g[j])) +
                         ((b[k] - g[j]) * (b[k] - g[j])) +
                         ((r[i] - b[k]) * (r[i] - b[k])));
    }
  }
  for (k = 0; k < nb; k++) {
    i = lower_bound(r.begin(), r.end(), b[k]) - r.begin();
    if (i >= nr) break;
    j = lower_bound(g.begin(), g.end(), r[i]) - g.begin();
    if (j >= ng) break;
    a = (g[j] + b[k]) / 2;
    i = lower_bound(r.begin(), r.end(), a) - r.begin();
    if (i < nr && r[i] <= g[j]) {
      ans = min(ans, ((r[i] - g[j]) * (r[i] - g[j])) +
                         ((b[k] - g[j]) * (b[k] - g[j])) +
                         ((r[i] - b[k]) * (r[i] - b[k])));
    }
    i--;
    if (i >= 0 && r[i] >= b[k]) {
      ans = min(ans, ((r[i] - g[j]) * (r[i] - g[j])) +
                         ((b[k] - g[j]) * (b[k] - g[j])) +
                         ((r[i] - b[k]) * (r[i] - b[k])));
    }
  }
  for (k = 0; k < nb; k++) {
    j = lower_bound(g.begin(), g.end(), b[k]) - g.begin();
    if (j >= ng) break;
    i = lower_bound(r.begin(), r.end(), g[j]) - r.begin();
    if (i >= nr) break;
    a = (r[i] + b[k]) / 2;
    j = lower_bound(g.begin(), g.end(), a) - g.begin();
    if (j < ng && g[j] <= r[i]) {
      ans = min(ans, ((r[i] - g[j]) * (r[i] - g[j])) +
                         ((b[k] - g[j]) * (b[k] - g[j])) +
                         ((r[i] - b[k]) * (r[i] - b[k])));
    }
    j--;
    if (j >= 0 && g[j] >= b[k]) {
      ans = min(ans, ((r[i] - g[j]) * (r[i] - g[j])) +
                         ((b[k] - g[j]) * (b[k] - g[j])) +
                         ((r[i] - b[k]) * (r[i] - b[k])));
    }
  }
  cout << ans << "\n";
}
signed main() {
  std::ios_base::sync_with_stdio(false);
  long long int t = 1;
  cin >> t;
  long long int cas = 1;
  while (cas <= t) {
    shikhar7s(cas);
    cas++;
  }
  return 0;
}
