#include <bits/stdc++.h>
using namespace std;
void faster() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
const long long INF = 4e18;
const long long MAXN = 1e6 + 100;
const long long MOD = 1e9 + 7;
long long n[3];
vector<pair<long long, long long>> v;
vector<long long> a[3];
long long clac(long long x, long long y, long long z) {
  return (x - y) * (x - y) + (x - z) * (x - z) + (y - z) * (y - z);
}
void solve() {
  v.clear();
  for (int i = 0; i < 3; ++i) {
    cin >> n[i];
    a[i].clear();
  }
  for (int i = 0; i < 3; ++i) {
    for (int j = 0, x; j < n[i]; ++j) {
      cin >> x;
      v.push_back({x, i});
    }
  }
  long long ans = INF, l[3] = {-1, -1, -1};
  sort(v.begin(), v.end());
  for (auto &&[x, y] : v) {
    a[y].push_back(x);
    l[y] = x;
    if (l[0] == -1 || l[1] == -1 || l[2] == -1) continue;
    for (int j = 0; j < 3; ++j) {
      if (j != y) {
        for (int z : a[j]) {
          ans = min(ans, clac(l[y], z, l[3 - y - j]));
        }
      }
    }
    ans = min(clac(l[0], l[1], l[2]), ans);
    for (int j = 0; j < 3; ++j) {
      if (j != y) {
        a[j].clear();
      }
    }
  }
  cout << ans << '\n';
}
int main() {
  faster();
  int T = 1;
  cin >> T;
  while (T--) {
    solve();
  }
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  return 0;
}
