#include <bits/stdc++.h>
using namespace std;
void boostIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
const int maxn = 1e5 + 5;
const int unsigned long long inf = 1999999996000000002;
int t;
int n[3];
int a[3][maxn];
unsigned long long get(unsigned long long x, unsigned long long y,
                       unsigned long long z) {
  return (x - y) * (x - y) + (x - z) * (x - z) + (y - z) * (y - z);
}
unsigned long long solve(int i, int j, int k) {
  unsigned long long ans = inf;
  for (int c = 0; c < n[i]; ++c) {
    int idx1 = lower_bound(a[j], a[j] + n[j], a[i][c]) - a[j];
    if (idx1 == n[j])
      idx1 = n[j] - 1;
    else if (idx1 == 0 && a[j][idx1] > a[i][c])
      continue;
    else if (idx1 > 0 && a[j][idx1] > a[i][c])
      --idx1;
    int idx2 = lower_bound(a[k], a[k] + n[k], a[i][c]) - a[k];
    if (idx2 == n[k]) return ans;
    ans = min(ans, get(a[j][idx1], a[k][idx2], a[i][c]));
  }
  return ans;
}
int main() {
  boostIO();
  cin >> t;
  while (t--) {
    unsigned long long ans = inf;
    for (int i = 0; i < 3; ++i) cin >> n[i];
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < n[i]; ++j) cin >> a[i][j];
      sort(a[i], a[i] + n[i]);
    }
    vector<int> perm = {0, 1, 2};
    do {
      ans = min(ans, solve(perm[0], perm[1], perm[2]));
    } while (next_permutation(perm.begin(), perm.end()));
    cout << ans << '\n';
  }
  return 0;
}
