#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <typename T>
istream& operator>>(istream& in, vector<T>& a) {
  for (auto& i : a) in >> i;
  return in;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T>& a) {
  for (auto& i : a) out << i << " ";
  return out;
}
template <typename T, typename U>
void chkmin(T& a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
void chkmax(T& a, U b) {
  if (a < b) a = b;
}
void solve() {
  vector<int> sizes(3);
  cin >> sizes;
  vector<vector<int>> a(3);
  for (int i = (int)0; i < (int)3; i++) {
    a[i].resize(sizes[i]);
    cin >> a[i];
    sort((a[i]).begin(), (a[i]).end());
  }
  vector<int> p(3);
  iota((p).begin(), (p).end(), 0);
  long long ans = 4e18;
  do {
    auto b = a;
    for (int i = (int)0; i < (int)3; i++) b[i] = a[p[i]];
    for (int x : b[0]) {
      auto Y = upper_bound((b[1]).begin(), (b[1]).end(), x);
      if (Y == b[1].begin()) continue;
      auto Z = lower_bound((b[2]).begin(), (b[2]).end(), x);
      if (Z == b[2].end()) continue;
      int y = *(--Y), z = *Z;
      chkmin(ans, 1LL * (x - y) * (x - y) + 1LL * (y - z) * (y - z) +
                      1LL * (z - x) * (z - x));
    }
  } while (next_permutation((p).begin(), (p).end()));
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int t;
  cin >> t;
  while (t-- > 0) solve();
  return 0;
}
