#include <bits/stdc++.h>
using namespace std;
int N[3];
int A[3][200005];
void Read() {
  scanf("%d%d%d", &N[0], &N[1], &N[2]);
  for (int i = 1; i <= N[0]; i++) {
    scanf("%d", &A[0][i]);
  }
  for (int i = 1; i <= N[1]; i++) {
    scanf("%d", &A[1][i]);
  }
  for (int i = 1; i <= N[2]; i++) {
    scanf("%d", &A[2][i]);
  }
  for (int i = 0; i < 3; i++) sort(A[i] + 1, A[i] + N[i] + 1);
}
int findNext(int ind, int val) {
  int left = 1, right = N[ind], mid, sol = -1;
  while (left <= right) {
    mid = (left + right) / 2;
    if (A[ind][mid] >= val) {
      sol = A[ind][mid];
      right = mid - 1;
    } else
      left = mid + 1;
  }
  return sol;
}
int findPrev(int ind, int val) {
  int left = 1, right = N[ind], mid, sol = -1;
  while (left <= right) {
    mid = (left + right) / 2;
    if (A[ind][mid] <= val) {
      sol = A[ind][mid];
      left = mid + 1;
    } else
      right = mid - 1;
  }
  return sol;
}
long long Dist(int a, int b, int c) {
  if (a == -1 || b == -1 || c == -1) return 3000000000000000001;
  return (1LL * (a - b) * (a - b)) + (1LL * (b - c) * (b - c)) +
         (1LL * (a - c) * (a - c));
}
void Solve() {
  long long ans = -1;
  for (int i = 1; i <= N[0]; i++) {
    int left = findPrev(1, A[0][i]);
    int right = findNext(2, A[0][i]);
    long long dist = Dist(left, A[0][i], right);
    ans = (ans == -1 ? dist : min(ans, dist));
    left = findPrev(2, A[0][i]);
    right = findNext(1, A[0][i]);
    dist = Dist(left, A[0][i], right);
    ans = (ans == -1 ? dist : min(ans, dist));
  }
  for (int i = 1; i <= N[1]; i++) {
    int left = findPrev(2, A[1][i]);
    int right = findNext(0, A[1][i]);
    long long dist = Dist(left, A[1][i], right);
    ans = (ans == -1 ? dist : min(ans, dist));
    left = findPrev(0, A[1][i]);
    right = findNext(2, A[1][i]);
    dist = Dist(left, A[1][i], right);
    ans = (ans == -1 ? dist : min(ans, dist));
  }
  for (int i = 1; i <= N[2]; i++) {
    int left = findPrev(0, A[2][i]);
    int right = findNext(1, A[2][i]);
    long long dist = Dist(left, A[2][i], right);
    ans = (ans == -1 ? dist : min(ans, dist));
    left = findPrev(1, A[2][i]);
    right = findNext(0, A[2][i]);
    dist = Dist(left, A[2][i], right);
    ans = (ans == -1 ? dist : min(ans, dist));
  }
  printf("%I64d\n", ans);
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    Read();
    Solve();
  }
  return 0;
}
