#include <bits/stdc++.h>
using namespace std;
const int N = 100050;
const int inf = 0x3f3f3f3f;
const long long mod = 998244353LL;
clock_t TIME_START, TIME_END;
void program_end() {}
inline long long cal(long long x, long long y, long long z) {
  return (x - y) * (x - y) + (x - z) * (x - z) + (y - z) * (y - z);
}
long long a[N], b[N], c[N];
long long s[10];
long long ans;
inline void work(long long A[N], long long B[N], long long C[N], int na, int nb,
                 int nc) {
  memset(s, 0, sizeof(s));
  vector<pair<long long, int>> pll;
  for (int i = 1; i <= na; ++i) pll.push_back({A[i], 1});
  for (int i = 1; i <= nb; ++i) pll.push_back({B[i], 2});
  sort(pll.begin(), pll.end());
  int sz = pll.size();
  for (int i = 0; i < sz; ++i) {
    s[pll[i].second] = pll[i].first;
    if (s[1] == 0 || s[2] == 0) continue;
    long long mid = (s[1] + s[2]) >> 1;
    int it = lower_bound(C + 1, C + nc + 1, mid) - C;
    if (it <= nc) ans = min(ans, cal(s[1], s[2], C[it]));
    if (it > 1) ans = min(ans, cal(s[1], s[2], C[it - 1]));
    if (it < nc) ans = min(ans, cal(s[1], s[2], C[it + 1]));
  }
}
int na, nb, nc;
void solve() {
  ans = LLONG_MAX;
  scanf("%d%d%d", &na, &nb, &nc);
  for (int i = 1; i <= na; ++i) scanf("%lld", &a[i]);
  for (int i = 1; i <= nb; ++i) scanf("%lld", &b[i]);
  for (int i = 1; i <= nc; ++i) scanf("%lld", &c[i]);
  sort(a + 1, a + na + 1);
  sort(b + 1, b + nb + 1);
  sort(c + 1, c + nc + 1);
  work(a, b, c, na, nb, nc);
  work(a, c, b, na, nc, nb);
  work(b, a, c, nb, na, nc);
  printf("%lld\n", ans);
}
int main() {
  TIME_START = clock();
  int Test = 1;
  cin >> Test;
  while (Test--) solve();
  TIME_END = clock();
  program_end();
  return 0;
}
