#include <bits/stdc++.h>
using namespace std;
const long long N = (long long)(1e6) + 322;
const long long MAXN = (long long)(1e7) + 100;
const long long inf = (long long)(3e18) + 322;
const long long mod = (long long)(1e9) + 7;
const double eps = 1e-6;
inline void upd(long long &mn, long long x, long long y, long long z) {
  mn = min(mn, (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x));
}
void solve() {
  long long mn = inf;
  long long n1, n2, n3;
  vector<long long> v[4];
  cin >> n1 >> n2 >> n3;
  for (long long i = 1; i <= n1; ++i) {
    long long x;
    cin >> x;
    v[0].push_back(x);
  }
  sort((v[0]).begin(), (v[0]).end());
  for (long long i = 1; i <= n2; ++i) {
    long long x;
    cin >> x;
    v[1].push_back(x);
  }
  sort((v[1]).begin(), (v[1]).end());
  for (long long i = 1; i <= n3; ++i) {
    long long x;
    cin >> x;
    v[2].push_back(x);
  }
  sort((v[2]).begin(), (v[2]).end());
  vector<long long> ids;
  for (long long i = 0; i < 3; ++i) {
    ids.push_back(i);
  }
  do {
    for (long long i = 0; i < (long long)(v[ids[0]].size()); ++i) {
      long long x = v[ids[0]][i];
      auto z = lower_bound((v[ids[2]]).begin(), (v[ids[2]]).end(), x);
      if (z == v[ids[2]].end()) continue;
      auto y =
          lower_bound((v[ids[1]]).begin(), (v[ids[1]]).end(), (x + *z) / 2);
      if (y != v[ids[1]].end()) upd(mn, x, *y, *z);
      if (y != v[ids[1]].begin()) {
        auto y2 =
            --lower_bound((v[ids[1]]).begin(), (v[ids[1]]).end(), (x + *z) / 2);
        upd(mn, x, *y2, *z);
      }
    }
  } while (next_permutation((ids).begin(), (ids).end()));
  cout << mn << "\n";
}
signed main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  long long test;
  cin >> test;
  for (long long tt = 1; tt <= test; ++tt) {
    solve();
  }
  return 0;
}
