#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 10;
const int MAXN = 1e5 + 10;
long long mul(long long x, long long y) { return (x * 1ll * y) % 1000000007; }
long long add(long long x, long long y) {
  x += y;
  while (x >= 1000000007) x -= 1000000007;
  while (x < 0) x += 1000000007;
  return x;
}
bool isPrime(long long n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
long long an;
long long sq(long long x) { return 1ll * x * x; }
void go(vector<long long> &r, vector<long long> &g, vector<long long> &b) {
  for (long long pr : r) {
    auto x = lower_bound((g).begin(), (g).end(), pr);
    auto y = upper_bound((b).begin(), (b).end(), pr);
    if (x == g.end() || y == b.begin()) continue;
    y--;
    long long a = sq(pr - *x);
    long long b = sq(*x - *y);
    long long c = sq(*y - pr);
    an = min(an, a + b + c);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    int nr, ng, nb;
    cin >> nr >> ng >> nb;
    vector<long long> r(nr), g(ng), 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((g).begin(), (g).end());
    sort((b).begin(), (b).end());
    an = 9e18;
    go(r, g, b);
    go(r, b, g);
    go(g, r, b);
    go(g, b, r);
    go(b, r, g);
    go(b, g, r);
    cout << an << endl;
  }
}
