#include <bits/stdc++.h>
using namespace std;
const int INF_I = 1e9;
const long long INF_LL = 1e18;
const int MOD = 1000000007;
const double eps = 1e-6;
long long foo(long long a, long long b, long long c) {
  return (a - b) * (a - b) + (c - b) * (c - b) + (a - c) * (a - c);
}
void solve() {
  int nr, ng, nb;
  cin >> nr >> ng >> nb;
  vector<int> r(nr), g(ng), b(nb);
  for (int i = 0; i < nr; i++) cin >> r[i];
  for (int i = 0; i < ng; i++) cin >> g[i];
  for (int i = 0; i < nb; i++) cin >> b[i];
  sort(begin(r), end(r));
  sort(begin(g), end(g));
  sort(begin(b), end(b));
  long long mn = LLONG_MAX;
  for (int i = 0; i < nr; i++) {
    int k1 = lower_bound(begin(g), end(g), r[i]) - g.begin();
    int k2 = upper_bound(begin(b), end(b), r[i]) - b.begin() - 1;
    if (k1 < ng && k2 >= 0) mn = min(mn, foo(r[i], g[k1], b[k2]));
    k1 = lower_bound(begin(b), end(b), r[i]) - b.begin();
    k2 = upper_bound(begin(g), end(g), r[i]) - g.begin() - 1;
    if (k1 < nb && k2 >= 0) mn = min(mn, foo(r[i], b[k1], g[k2]));
  }
  for (int i = 0; i < ng; i++) {
    int k1 = lower_bound(begin(r), end(r), g[i]) - r.begin();
    int k2 = upper_bound(begin(b), end(b), g[i]) - b.begin() - 1;
    if (k1 < nr && k2 >= 0) mn = min(mn, foo(g[i], r[k1], b[k2]));
    k1 = lower_bound(begin(b), end(b), g[i]) - b.begin();
    k2 = upper_bound(begin(r), end(r), g[i]) - r.begin() - 1;
    if (k1 < nb && k2 >= 0) mn = min(mn, foo(g[i], b[k1], r[k2]));
  }
  for (int i = 0; i < nb; i++) {
    int k1 = lower_bound(begin(r), end(r), b[i]) - r.begin();
    int k2 = upper_bound(begin(g), end(g), b[i]) - g.begin() - 1;
    if (k1 < nr && k2 >= 0) mn = min(mn, foo(b[i], r[k1], g[k2]));
    k1 = lower_bound(begin(g), end(g), b[i]) - g.begin();
    k2 = upper_bound(begin(r), end(r), b[i]) - r.begin() - 1;
    if (k1 < ng && k2 >= 0) mn = min(mn, foo(b[i], g[k1], r[k2]));
  }
  cout << mn << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
