#include <bits/stdc++.h>
using namespace std;
const long long inf = 4e18;
const long long mod = 1e9 + 7;
const long long N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline long long calc(long long x, long long y, long long z) {
  return (x - y) * (x - y) + (y - z) * (y - z) + (x - z) * (x - z);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  ;
  while (t--) {
    long long na, nb, nc;
    cin >> na >> nb >> nc;
    ;
    vector<pair<long long, long long> > v;
    for (long long i = (1); i <= (na); i++) {
      long long x;
      cin >> x;
      ;
      v.push_back({x, 0});
    }
    for (long long i = (1); i <= (nb); i++) {
      long long x;
      cin >> x;
      ;
      v.push_back({x, 1});
    }
    for (long long i = (1); i <= (nc); i++) {
      long long x;
      cin >> x;
      ;
      v.push_back({x, 2});
    }
    sort(v.begin(), v.end());
    long long n = (long long)(v.size());
    vector<vector<long long> > f(n + 4, vector<long long>(3, 0));
    vector<vector<long long> > bb(n + 4, vector<long long>(3, inf));
    f[0][v[0].second] = v[0].first;
    for (long long i = (1); i <= (n - 1); i++) {
      pair<long long, long long> x = v[i];
      for (long long j = (0); j <= (2); j++) f[i][j] = f[i - 1][j];
      f[i][x.second] = x.first;
    }
    for (long long i = (n - 1); i >= (0); i--) {
      pair<long long, long long> x = v[i];
      for (long long j = (0); j <= (2); j++) bb[i][j] = bb[i + 1][j];
      bb[i][x.second] = x.first;
    }
    long long ans = inf;
    for (long long i = (1); i <= (n - 1); i++) {
      pair<long long, long long> qq = v[i];
      long long col = qq.second, x = qq.first, a, b;
      if (col == 0) a = 1, b = 2;
      if (col == 1) a = 0, b = 2;
      if (col == 2) a = 0, b = 1;
      if (f[i][a] > 0 && f[i][b] > 0) ans = min(ans, calc(x, f[i][a], f[i][b]));
      if (f[i][a] > 0 && bb[i][b] < inf)
        ans = min(ans, calc(x, f[i][a], bb[i][b]));
      if (f[i][b] > 0 && bb[i][a] < inf)
        ans = min(ans, calc(x, f[i][b], bb[i][a]));
      if (bb[i][a] < inf && bb[i][b] < inf)
        ans = min(ans, calc(x, bb[i][a], bb[i][b]));
    }
    cout << ans << '\n';
    ;
  }
}
