#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const long long inf = 3e18;
vector<int> a1, a2, a3;
int n1, n2, n3;
long long mn;
void input(int n, vector<int> &a) {
  a.resize(0);
  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;
    a.push_back(v);
  }
  sort((a).begin(), (a).end());
}
long long calc(int a, int b, int c) {
  return (a - b) * 1ll * (a - b) + (b - c) * 1ll * (b - c) +
         (a - c) * 1ll * (a - c);
}
void ans(vector<int> &v1, vector<int> &v2, vector<int> &v3) {
  for (int i : v2) {
    int j = lower_bound(v1.begin(), v1.end(), i) - v1.begin();
    int k = lower_bound(v3.begin(), v3.end(), i) - v3.begin();
    if (j == v1.size()) j--;
    if (k == v3.size()) k--;
    mn = min(mn, calc(i, v1[j], v3[k]));
    if (j > 0) mn = min(mn, calc(i, v1[j - 1], v3[k]));
    if (j + 1 < v1.size()) mn = min(mn, calc(i, v1[j + 1], v3[k]));
    if (k > 0) mn = min(mn, calc(i, v1[j], v3[k - 1]));
    if (k + 1 < v3.size()) mn = min(mn, calc(i, v1[j], v3[k + 1]));
    if (j > 0 && k > 0) mn = min(mn, calc(i, v1[j - 1], v3[k - 1]));
    if (j + 1 < v1.size() && k + 1 < v3.size())
      mn = min(mn, calc(i, v1[j + 1], v3[k + 1]));
  }
}
void solve() {
  cin >> n1 >> n2 >> n3;
  mn = inf;
  input(n1, a1);
  input(n2, a2);
  input(n3, a3);
  ans(a1, a2, a3);
  ans(a3, a1, a2);
  ans(a1, a3, a2);
  cout << mn << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t, p;
  cin >> t;
  for (p = 1; p <= t; p++) {
    solve();
  }
  return 0;
}
