#include <bits/stdc++.h>
using namespace std;
int q, dim[4], target;
unsigned long long sol;
set<unsigned long long> segm[4];
void incearca(unsigned long long a, unsigned long long b,
              unsigned long long c) {
  sol = min(sol, (a - b) * (a - b) + (a - c) * (a - c) + (b - c) * (b - c));
}
void solve(int ord1, int ord2, int ord3) {
  set<unsigned long long>::iterator mare = segm[ord3].begin();
  set<unsigned long long>::iterator mediu = segm[ord2].begin();
  for (int a : segm[ord1]) {
    while (*mare < a && mare != segm[ord3].end()) mare++;
    if (mare == segm[ord3].end()) return;
    int c = *mare;
    while (*mediu <= (a + c) / 2 && mediu != segm[ord2].end()) mediu++;
    if (mediu != segm[ord2].begin()) mediu--;
    int b = *mediu;
    incearca(a, b, c);
    if (b < (a + c) / 2) {
      mediu++;
      if (mediu != segm[ord2].end()) incearca(a, *mediu, c);
      mediu--;
    }
  }
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> q;
  while (q--) {
    sol = 18446744073709551615;
    cin >> dim[1] >> dim[2] >> dim[3];
    for (int i = 1; i <= 3; i++) {
      segm[i].clear();
      for (int j = 1; j <= dim[i]; j++) {
        int nr;
        cin >> nr;
        segm[i].insert(nr);
      }
    }
    solve(1, 2, 3);
    solve(1, 3, 2);
    solve(2, 1, 3);
    solve(2, 3, 1);
    solve(3, 1, 2);
    solve(3, 2, 1);
    cout << sol << '\n';
  }
  return 0;
}
