#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<P, ll>;
using PP = pair<P, P>;
constexpr int INF = 1 << 28;
constexpr ll MOD = ll(1e9) + 7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr int di8[] = {0, 1, 1, 1, 0, -1, -1, -1};
constexpr int dj8[] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr double EPS = 1e-9;
ll f(ll x, ll y, ll z) {
  return (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x);
}
int solve() {
  int n[3];
  for (int i = 0; i < 3; i++) scanf("%d", &n[i]);
  vector<vector<ll> > w(3);
  for (int i = 0; i < 3; i++) {
    w[i].resize(n[i]);
    for (int j = 0; j < n[i]; j++) {
      scanf("%lld", &w[i][j]);
    }
    sort(w[i].begin(), w[i].end());
  }
  ll ans = 1LL << 62;
  int r = 5;
  for (int i = 0; i < n[0]; i++) {
    int p1 = lower_bound(w[1].begin(), w[1].end(), w[0][i]) - w[1].begin();
    int p2 = lower_bound(w[2].begin(), w[2].end(), w[0][i]) - w[2].begin();
    int idx[3];
    idx[0] = i;
    for (int j = -r; j <= r; j++) {
      idx[1] = p1 + j;
      if (idx[1] < 0 || idx[1] >= n[1]) continue;
      for (int k = -r; k <= r; k++) {
        idx[2] = p2 + k;
        if (idx[2] < 0 || idx[2] >= n[2]) continue;
        ans = min(ans, f(w[0][idx[0]], w[1][idx[1]], w[2][idx[2]]));
      }
    }
  }
  for (int i = 0; i < n[1]; i++) {
    int p1 = lower_bound(w[0].begin(), w[0].end(), w[1][i]) - w[0].begin();
    int p2 = lower_bound(w[2].begin(), w[2].end(), w[1][i]) - w[2].begin();
    int idx[3];
    idx[1] = i;
    for (int j = -r; j <= r; j++) {
      idx[0] = p1 + j;
      if (idx[0] < 0 || idx[0] >= n[0]) continue;
      for (int k = -r; k <= r; k++) {
        idx[2] = p2 + k;
        if (idx[2] < 0 || idx[2] >= n[2]) continue;
        ans = min(ans, f(w[0][idx[0]], w[1][idx[1]], w[2][idx[2]]));
      }
    }
  }
  for (int i = 0; i < n[2]; i++) {
    int p1 = lower_bound(w[1].begin(), w[1].end(), w[2][i]) - w[1].begin();
    int p2 = lower_bound(w[0].begin(), w[0].end(), w[2][i]) - w[0].begin();
    int idx[3];
    idx[2] = i;
    for (int j = -r; j <= r; j++) {
      idx[1] = p1 + j;
      if (idx[1] < 0 || idx[1] >= n[1]) continue;
      for (int k = -r; k <= r; k++) {
        idx[0] = p2 + k;
        if (idx[0] < 0 || idx[0] >= n[0]) continue;
        ans = min(ans, f(w[0][idx[0]], w[1][idx[1]], w[2][idx[2]]));
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
int main() {
  int t;
  cin >> t;
  for (; t > 0; t--) solve();
  return 0;
}
