#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
void ingraph(vector<long long> graph[], long long m) {
  long long x, y;
  for (long long i = 0; i < m; i++) {
    cin >> x >> y;
    x--, y--;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long modmulti(long long a, long long b) {
  return ((a % mod) * 1ll * (b % mod)) % mod;
}
long long modadd(long long a, long long b) {
  long long asdfgh = ((a % mod) + (b % mod) + mod + mod) % mod;
  asdfgh = (asdfgh + mod) % mod;
  return asdfgh;
}
long long modpower(long long a, long long n) {
  if (n == 0) return 1;
  if (n == 1) return a % mod;
  long long b = modpower(a, n / 2);
  b = modmulti(b, b);
  if (n % 2 == 0) return b;
  return modmulti(a, b);
}
long long modinv(long long a) { return modpower(a, mod - 2); }
long long solve(long long a, long long b, long long c) {
  long long ans = (a - b) * (a - b) + (a - c) * (a - c) + (b - c) * (b - c);
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long g, b, r;
    cin >> r >> g >> b;
    vector<pair<long long, long long> > vec;
    for (long long i = 0; i < r; i++) {
      long long a;
      cin >> a;
      vec.push_back({a, 0});
    }
    for (long long i = 0; i < g; i++) {
      long long a;
      cin >> a;
      vec.push_back({a, 1});
    }
    for (long long i = 0; i < b; i++) {
      long long a;
      cin >> a;
      vec.push_back({a, 2});
    }
    sort(vec.begin(), vec.end());
    long long i = 0, j = 0;
    long long n = (long long)(vec).size();
    long long ans = LLONG_MAX;
    while (i < n && j < n) {
      long long x = LLONG_MAX, y = LLONG_MAX;
      x = vec[i].first;
      vector<long long> v;
      while (i < n && vec[i].second == vec[i + 1].second) {
        i++;
        if (i < n) x = vec[i].first;
      }
      j = i + 1;
      v.push_back(vec[j].first);
      while (j < n && vec[j].second == vec[j + 1].second) {
        j++;
        if (j < n) v.push_back(vec[j].first);
      }
      if (j + 1 < n && vec[i].second != vec[j + 1].second) y = vec[j + 1].first;
      if (y != LLONG_MAX) {
        for (long long k = 0; k < (long long)(v).size(); k++) {
          ans = min(ans, solve(x, v[k], y));
        }
      }
      i++;
    }
    cout << ans << '\n';
  }
  return 0;
}
