#include <bits/stdc++.h>
using namespace std;
int const mod = 998244353;
int const N = 200200;
int a[3][N], nu[3];
int st[3];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    for (int i = 0; i < (3); ++i) scanf("%d", &nu[i]);
    for (int i = 0; i < (3); ++i) {
      for (int j = 0; j < (nu[i]); ++j) scanf("%d", &a[i][j]);
      sort(a[i], a[i] + nu[i]);
    }
    for (int i = 0; i < (3); ++i) st[i] = i;
    long long ans = 0x3FFFFFFFFFFFFFFFLL;
    do {
      int p1 = 0, p2 = 0, p3 = 0;
      while (p1 < nu[st[0]]) {
        long long x = a[st[0]][p1];
        while (p2 + 1 < nu[st[1]] && x >= a[st[1]][p2 + 1]) ++p2;
        while (p3 < nu[st[2]] && x > a[st[2]][p3]) ++p3;
        if (p3 == nu[st[2]]) break;
        long long y = a[st[1]][p2];
        long long z = a[st[2]][p3];
        ans =
            min(ans, (x - y) * (x - y) + (x - z) * (x - z) + (y - z) * (y - z));
        ++p1;
      }
    } while (next_permutation(st, st + 3));
    printf("%I64d\n", ans);
  }
  return 0;
}
