#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int T, a[3][N], p[] = {0, 1, 2};
long long res;
void solve() {
  int t1 = 1, t2 = 1;
  for (int i = 1; i <= a[p[0]][0]; i++) {
    long long y = a[p[0]][i];
    while (t1 < a[p[1]][0] && a[p[1]][t1 + 1] <= y) t1++;
    while (t2 < a[p[2]][0] && a[p[2]][t2] < y) t2++;
    long long x = a[p[1]][t1], z = a[p[2]][t2];
    res = min(res, (x - y) * (x - y) + (x - z) * (x - z) + (y - z) * (y - z));
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  scanf("%d", &T);
  while (T--) {
    res = 9e18;
    scanf("%d%d%d", &a[0], &a[1], &a[2]);
    for (int k = 0; k < 3; k++) {
      for (int i = 1; i <= a[k][0]; i++) scanf("%d", &a[k][i]);
      sort(a[k] + 1, a[k] + a[k][0] + 1);
    }
    do {
      solve();
    } while (next_permutation(p, p + 3));
    printf("%lld\n", res);
  }
}
