#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7, inf = 1e9 + 5;
long long g, h, l;
const long long N = 100005;
long long add(long long a, long long b, long long MOD);
long long mul(long long a, long long b, long long MOD);
long long binpo(long long a, long long b);
long long calc(long long a, long long b, long long c) {
  return binpo(a - b, 2) + binpo(c - b, 2) + binpo(a - c, 2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long TESTS = 1;
  cin >> TESTS;
  for (long long i = 1; i <= TESTS; i++) {
    long long nr, ng, nb;
    cin >> nr >> ng >> nb;
    vector<long long> v[3];
    for (long long i = 0; i < nr; i++) {
      cin >> g;
      v[0].push_back(g);
    }
    for (long long i = 0; i < ng; i++) {
      cin >> g;
      v[1].push_back(g);
    }
    for (long long i = 0; i < nb; i++) {
      cin >> g;
      v[2].push_back(g);
    }
    long long mini = LLONG_MAX;
    sort(v[0].begin(), v[0].end());
    sort(v[1].begin(), v[1].end());
    sort(v[2].begin(), v[2].end());
    v[0].resize(unique(v[0].begin(), v[0].end()) - v[0].begin());
    v[1].resize(unique(v[1].begin(), v[1].end()) - v[1].begin());
    v[2].resize(unique(v[2].begin(), v[2].end()) - v[2].begin());
    long long per[] = {0, 1, 2};
    do {
      vector<long long> r = v[per[0]];
      vector<long long> g = v[per[1]];
      vector<long long> b = v[per[2]];
      for (long long i = 0; i < (long long)r.size(); i++) {
        vector<long long> t1;
        long long idx = lower_bound(g.begin(), g.end(), r[i]) - g.begin();
        if (idx != (long long)g.size()) t1.push_back(idx);
        if (idx + 1 < (long long)g.size()) {
          t1.push_back(idx + 1);
        }
        if (idx) {
          t1.push_back(idx - 1);
        }
        vector<long long> t2;
        for (auto j : t1) {
          idx = lower_bound(b.begin(), b.end(), (g[j] + r[i]) / 2) - b.begin();
          if (idx != (long long)b.size()) t2.push_back(idx);
          if (idx + 1 < (long long)b.size()) {
            t2.push_back(idx + 1);
          }
          if (idx) {
            t2.push_back(idx - 1);
          }
        }
        for (long long k = 0; k < (long long)t1.size(); k++) {
          for (long long l = 0; l < (long long)t2.size(); l++) {
            mini = min(mini, calc(r[i], g[t1[k]], b[t2[l]]));
          }
        }
      }
    } while (next_permutation(per, per + 3));
    cout << mini << endl;
  }
}
long long add(long long a, long long b) { return (a % MOD + b % MOD) % MOD; }
long long mul(long long a, long long b) { return (a * 1ll * b) % MOD; }
long long binpo(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b % 2 != 0) {
      ans = ans * a;
    }
    a = a * a;
    b = b / 2;
  }
  return ans;
}
