#include <bits/stdc++.h>
using namespace std;
const long long M = 1000000;
long long na, nb, nc, res;
vector<long long> a, b, c;
long long cal2(long long x) { return x * x; }
long long cal(long long x, long long y, long long z) {
  return cal2(x - y) + cal2(y - z) + cal2(z - x);
}
void calc(long long val, long long x, long long y, long long u, long long v) {
  for (int i = x; i <= y; i++)
    for (int j = u; j <= v; j++) res = min(res, cal(val, b[i], c[j]));
}
void solve2() {
  long long j = 0, k = 0;
  for (auto h : a) {
    while (j < b.size() && b[j] < h) j++;
    while (k < c.size() && c[k] < h) k++;
    long long x = max((long long)0, j - 1),
              y = min((long long)(b.size() - 1), j + 1);
    long long u = max((long long)0, k - 1),
              v = min((long long)(c.size() - 1), k + 1);
    calc(h, x, y, u, v);
  }
}
void solve() {
  a.clear();
  b.clear();
  c.clear();
  cin >> na >> nb >> nc;
  a.assign(na, 0);
  b.assign(nb, 0);
  c.assign(nc, 0);
  for (int i = 0; i < na; i++) cin >> a[i];
  for (int i = 0; i < nb; i++) cin >> b[i];
  for (int i = 0; i < nc; i++) cin >> c[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  a.erase(unique(a.begin(), a.end()), a.end());
  b.erase(unique(b.begin(), b.end()), b.end());
  c.erase(unique(c.begin(), c.end()), c.end());
  res = 9000000000000000000;
  solve2();
  swap(a, b);
  solve2();
  swap(a, c);
  solve2();
  cout << res << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long T = 1;
  cin >> T;
  for (int i = 1; i <= T; i++) {
    solve();
  }
  return 0;
}
