#include <bits/stdc++.h>
using namespace std;
const long double GOLDEN_RATIO =
    1.6180339887498949025257388711906969547271728515625;
const long double PI = 2.0 * acos(0.0);
const int BLOCK = 333;
long long calc(long long x, long long y, long long z) {
  long long a = x - y;
  long long b = x - z;
  long long c = y - z;
  long long ans = (a * a) + (b * b) + (c * c);
  return ans;
}
long long solve(vector<int> &a, vector<int> &b, vector<int> &c) {
  long long ans = LLONG_MAX;
  int tam = a.size();
  int k = 0, x1 = 0, x2 = 0;
  for (int i = 0; i < tam; i++) {
    while (k < c.size() && c[k] < a[i]) k++;
    if (k >= c.size()) break;
    while (x1 < b.size() && b[x1] < a[i]) x1++;
    while (x2 < b.size() && b[x2] < c[k]) x2++;
    int mediana = (x2 + x1) / 2;
    int l = max(0, mediana - 2);
    int r = min((int)b.size() - 1, mediana + 2);
    for (int j = l; j <= r; j++) ans = min(ans, calc(a[i], b[j], c[k]));
  }
  return ans;
}
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int T, R, G, B;
  cin >> T;
  while (T--) {
    cin >> R >> G >> B;
    vector<int> a(R), b(G), c(B);
    for (int i = 0; i < R; i++) cin >> a[i];
    for (int i = 0; i < G; i++) cin >> b[i];
    for (int i = 0; i < B; i++) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    (a).resize(unique(a.begin(), a.end()) - (a).begin());
    (b).resize(unique(b.begin(), b.end()) - (b).begin());
    (c).resize(unique(c.begin(), c.end()) - (c).begin());
    long long ans = solve(a, b, c);
    ans = min(ans, solve(a, c, b));
    ans = min(ans, solve(b, a, c));
    ans = min(ans, solve(b, c, a));
    ans = min(ans, solve(c, a, b));
    ans = min(ans, solve(c, b, a));
    cout << ans << '\n';
  }
  return 0;
}
