#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 3;
const long long INF = 4e18 + 3;
vector<long long> v[3];
int r[3];
long long ans;
auto iter1 = v[0].begin();
auto iter2 = v[1].begin();
long long X, Y;
void rob(int a, int b, int c) {
  for (auto it : v[b]) {
    if (it < v[a][0] || it > v[c].back()) continue;
    iter1 = upper_bound(v[a].begin(), v[a].end(), it);
    iter1--;
    iter2 = lower_bound(v[c].begin(), v[c].end(), it);
    X = *iter1;
    Y = *iter2;
    ans =
        min(ans, (X - Y) * (X - Y) + (X - it) * (X - it) + (Y - it) * (Y - it));
  }
}
int main() {
  int z;
  long long x;
  scanf("%d", &z);
  while (z--) {
    ans = INF;
    for (int i = 0; i < 3; i++) v[i].clear();
    for (int i = 0; i < 3; i++) scanf("%d", &r[i]);
    for (int i = 0; i < 3; i++) {
      for (int j = 1; j <= r[i]; j++) {
        scanf("%lld", &x);
        v[i].push_back(x);
      }
    }
    for (int i = 0; i < 3; i++) sort(v[i].begin(), v[i].end());
    rob(0, 1, 2);
    rob(0, 2, 1);
    rob(1, 0, 2);
    rob(1, 2, 0);
    rob(2, 0, 1);
    rob(2, 1, 0);
    printf("%lld\n", ans);
  }
  return 0;
}
