#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const char E = '\n';
const int N = 201015;
const int NN = 200005;
const long long md = 1e9 + 7;
long long f(long long a, long long b, long long c) {
  return (a - b) * (a - b) + (c - b) * (c - b) + (a - c) * (a - c);
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  int tttt;
  cin >> tttt;
  while (tttt--) {
    int nr, ng, nb;
    cin >> nr >> ng >> nb;
    vector<long long> r(nr);
    vector<long long> g(ng);
    vector<long long> b(nb);
    for (int i = 0; i < nr; i++) {
      cin >> r[i];
    }
    for (int i = 0; i < ng; i++) {
      cin >> g[i];
    }
    for (int i = 0; i < nb; i++) {
      cin >> b[i];
    }
    sort(r.begin(), r.end());
    sort(b.begin(), b.end());
    sort(g.begin(), g.end());
    long long ans = 5223372036854775807, cur;
    int l1 = 0, l2 = 0, l3 = 0;
    long long m1, m2, m3;
    while (true) {
      cur = f(r[l1], g[l2], b[l3]);
      ans = min(ans, cur);
      if (l1 + 1 == nr && l2 + 1 == ng && l3 + 1 == nb) {
        break;
      } else {
        m1 = 5223372036854775807;
        m2 = 5223372036854775807;
        m3 = 5223372036854775807;
        if (l1 + 1 < nr) {
          m1 = f(r[l1 + 1], g[l2], b[l3]);
        }
        if (l2 + 1 < ng) {
          m2 = f(r[l1], g[l2 + 1], b[l3]);
        }
        if (l3 + 1 < nb) {
          m3 = f(r[l1], g[l2], b[l3 + 1]);
        }
        ans = min(ans, min(m1, min(m2, m3)));
        if (m1 <= m2 && m1 <= m3) {
          l1++;
        } else if (m2 <= m1 && m2 <= m3) {
          l2++;
        } else {
          l3++;
        }
      }
    }
    cout << ans << E;
  }
  return 0;
}
