#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
bool cmax(T& a, const U& b) {
  return a < b ? a = b, 1 : 0;
}
template <class T, class U>
bool cmin(T& a, const U& b) {
  return b < a ? a = b, 1 : 0;
}
void _BG(const char* s) { cerr << s << endl; }
template <class T, class... TT>
void _BG(const char* s, T a, TT... b) {
  for (size_t c = 0; *s && (c || *s != ','); cerr << *s++)
    c += count(begin("([{"), end("([{"), *s) -
         count(begin(")]}"), end(")]}"), *s);
  cerr << " = " << a;
  if (*s) {
    cerr << ", ";
    ++s;
  }
  _BG(s, b...);
}
long long sqr(long long x) { return x * x; }
int n[3];
vector<int> v[3];
void solve() {
  for (int i = 0; i < 3; ++i) cin >> n[i];
  for (int i = 0; i < 3; ++i) {
    v[i].resize(n[i]);
    for (int& x : v[i]) cin >> x;
    sort(begin(v[i]), end(v[i]));
  }
  int p[3] = {0, 1, 2};
  long long ans = LLONG_MAX;
  do {
    int i = 0, j = 0;
    for (int y : v[p[1]]) {
      while (i + 1 < n[p[0]] && v[p[0]][i + 1] <= y) ++i;
      while (j < n[p[2]] && v[p[2]][j] < y) ++j;
      long long x, z;
      if (i < n[p[0]] && (x = v[p[0]][i]) <= y && j < n[p[2]] &&
          (z = v[p[2]][j]) >= y) {
        ans = min(ans, sqr(x - y) + sqr(x - z) + sqr(y - z));
      }
    }
  } while (next_permutation(p, p + 3));
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) solve();
}
