#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ul = unsigned long long;
using pii = pair<int, int>;
using vvi = vector<vector<int>>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
int t, n, k;
int upb(vector<int> &x, int a) {
  int ans = INT_MAX;
  int l = 0;
  int r = x.size() - 1;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (x[mid] >= a) {
      ans = x[mid];
      r = mid - 1;
    } else
      l = mid + 1;
  }
  return ans;
}
ll mini(ll a, ll b, ll c) {
  if (a < b && a < c)
    return a;
  else if (b < c)
    return b;
  else
    return c;
}
int lwb(vector<int> &x, int a) {
  int ans = INT_MAX;
  int l = 0;
  int r = x.size() - 1;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (x[mid] <= a) {
      ans = x[mid];
      l = mid + 1;
    } else
      r = mid - 1;
  }
  return ans;
}
inline ll dist(ll x, ll y, ll z) {
  return (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x);
}
ll calcmd(ll x, ll y, vector<int> &z) {
  ll idz = (x + y) / 2;
  ll izup = upb(z, idz);
  ll izlb = lwb(z, idz);
  return min(dist(x, y, izup), dist(x, y, izlb));
}
ll cl1(int a, vector<int> &y, vector<int> &z) {
  int xlby = lwb(y, a);
  int xuby = upb(y, a);
  ll md1 = calcmd(a, xlby, z);
  ll md2 = calcmd(a, xuby, z);
  return min(md1, md2);
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n1, n2, n3;
    cin >> n1 >> n2 >> n3;
    vector<int> x(n1);
    vector<int> y(n2);
    vector<int> z(n3);
    for (int i = 0; i < n1; i++) cin >> x[i];
    for (int i = 0; i < n2; i++) cin >> y[i];
    for (int i = 0; i < n3; i++) cin >> z[i];
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    sort(z.begin(), z.end());
    ll mi = LONG_LONG_MAX;
    for (int i = 0; i < n1; i++) {
      ll md1 = cl1(x[i], y, z);
      ll md2 = cl1(x[i], z, y);
      mi = mini(mi, md1, md2);
    }
    cout << mi << '\n';
  }
}
