#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long f[6][3] = {0, 1, 2, 1, 0, 2, 2, 0, 1, 0, 2, 1, 1, 0, 2, 2, 1, 0};
long long a[3][100005], l[3], m = 3, ans;
long long b[3][100005], tl[3];
void get(long long x, long long y, long long z) {
  long long t = (b[0][x] - b[1][y]) * (b[0][x] - b[1][y]) +
                (b[0][x] - b[2][z]) * (b[0][x] - b[2][z]) +
                (b[1][y] - b[2][z]) * (b[1][y] - b[2][z]);
  if (ans == -1 || ans > t) ans = t;
}
void check(long long p) {
  for (long long i = 0; i < m; i++) {
    tl[i] = l[f[p][i]];
    for (long long j = 1; j <= tl[i]; j++) b[i][j] = a[f[p][i]][j];
  }
  if (b[0][tl[0]] < b[1][1]) return;
  long long st = 1, t;
  for (long long i = 1; i <= tl[0]; i++) {
    while (st <= tl[1] && b[1][st] <= b[0][i]) st++;
    t = lower_bound(b[2] + 1, b[2] + tl[2] + 1, (b[1][st - 1] + b[0][i]) >> 1) -
        b[2];
    if (t <= tl[2] && st > 1) get(i, st - 1, t);
    t--;
    if (t > 0 && st > 1) get(i, st - 1, t);
  }
}
void solve() {
  for (long long i = 0; i < m; i++) cin >> l[i];
  for (long long i = 0; i < m; i++) {
    for (long long j = 1; j <= l[i]; j++) cin >> a[i][j];
    sort(a[i] + 1, a[i] + l[i] + 1);
  }
  ans = -1;
  for (long long i = 0; i < 6; i++) check(i);
  cout << ans << '\n';
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) solve();
  return 0;
}
