#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const long double pi = acos(-1.0);
const long double eps = 1e-5;
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3f;
const int maxn = 200010;
long long r[maxn];
long long g[maxn];
long long b[maxn];
long long ans;
int nr;
int ng;
int nb;
long long cal(long long x, long long y, long long z) {
  return (x - y) * (x - y) + (x - z) * (x - z) + (y - z) * (y - z);
}
void ty(long long* r, long long* g, long long* b, long long nr, long long ng,
        long long nb) {
  for (int i = (1); i <= (nr); i++) {
    int x = r[i];
    int p = lower_bound(g + 1, g + 1 + ng, x) - g;
    if (p <= ng) {
      int y = g[p];
      int p = lower_bound(b + 1, b + 1 + nb, x) - b;
      if (p <= nb) ans = min(ans, cal(x, y, b[p]));
      if (p > 1) ans = min(ans, cal(x, y, b[p - 1]));
    }
    if (p > 1) {
      int y = g[p - 1];
      int p = lower_bound(b + 1, b + 1 + nb, x) - b;
      if (p <= nb) ans = min(ans, cal(x, y, b[p]));
      if (p > 1) ans = min(ans, cal(x, y, b[p - 1]));
    }
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int nr, ng, nb;
    cin >> nr >> ng >> nb;
    for (int i = (1); i <= (nr); i++) cin >> r[i];
    for (int i = (1); i <= (ng); i++) cin >> g[i];
    for (int i = (1); i <= (nb); i++) cin >> b[i];
    sort(r + 1, r + 1 + nr);
    sort(g + 1, g + 1 + ng);
    sort(b + 1, b + 1 + nb);
    ans = INFLL;
    ty(r, g, b, nr, ng, nb);
    ty(r, b, g, nr, nb, ng);
    ty(g, r, b, ng, nr, nb);
    ty(g, b, r, ng, nb, nr);
    ty(b, r, g, nb, nr, ng);
    ty(b, g, r, nb, ng, nr);
    cout << ans << '\n';
  }
}
