#include <bits/stdc++.h>
using namespace std;
int T;
long long ans;
long long x, y, z;
long long r[2000050], g[2000050], b[2000050];
long long cal(long long a, long long b, long long c) {
  return (a - b) * (a - b) + (a - c) * (a - c) + (b - c) * (b - c);
}
void solve(long long A[], long long B[], long long C[], long long lena,
           long long lenb, long long lenc) {
  long long idb, idc;
  for (int i = 1; i <= lena; i++) {
    idb = lower_bound(B + 1, B + lenb + 1, A[i]) - B;
    idc = lower_bound(C + 1, C + lenc + 1, A[i]) - C;
    if (idb > lenb) idb--;
    if (idc > lenc) idc--;
    if (idb > 1) ans = min(ans, cal(A[i], B[idb - 1], C[idc]));
    if (idc > 1) ans = min(ans, cal(A[i], B[idb], C[idc - 1]));
    if (idb > 1 && idc > 1) ans = min(ans, cal(A[i], B[idb - 1], C[idc - 1]));
    ans = min(ans, cal(A[i], B[idb], C[idc]));
  }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> T;
  while (T--) {
    cin >> x >> y >> z;
    for (int i = 1; i <= x; i++) cin >> r[i];
    for (int i = 1; i <= y; i++) cin >> g[i];
    for (int i = 1; i <= z; i++) cin >> b[i];
    sort(r + 1, r + x + 1);
    sort(g + 1, g + y + 1);
    sort(b + 1, b + z + 1);
    ans = LLONG_MAX;
    solve(r, g, b, x, y, z);
    solve(g, r, b, y, x, z);
    solve(b, r, g, z, x, y);
    cout << ans << endl;
  }
  return 0;
}
