#include <bits/stdc++.h>
using namespace std;
long long int nr;
long long int ng;
long long int nb;
long long int r[1000000];
long long int g[1000000];
long long int b[1000000];
long long int cal(long long int x, long long int y, long long int z) {
  return ((x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x));
}
long long int calc(long long int x, long long int y, long long int z) {
  if (x < 0 || y < 0 || z < 0 || x >= nr || y >= ng || z >= nb)
    return LLONG_MAX;
  else
    return cal(r[x], g[y], b[z]);
}
long long int solve(long long int x, long long int y, long long int z) {
  long long int ans = LLONG_MAX;
  for (long long int i = -1; i <= 1; i++)
    for (long long int j = -1; j <= 1; j++)
      for (long long int k = -1; k <= 1; k++)
        ans = min(ans, calc(x + i, y + j, z + k));
  return ans;
}
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    cin >> nr >> ng >> nb;
    for (long long int i = 0; i < nr; i++) cin >> r[i];
    for (long long int i = 0; i < ng; i++) cin >> g[i];
    for (long long int i = 0; i < nb; i++) cin >> b[i];
    sort(r, r + nr), sort(g, g + ng), sort(b, b + nb);
    long long int i = 0, j = 0, k = 0;
    long long int ans = LLONG_MAX;
    while (i < nr || j < ng || k < nb) {
      ans = min(ans, solve(i, j, k));
      if (i < nr && (j >= ng || r[i] <= g[j]) && (k >= nb || r[i] <= b[k]))
        i++;
      else if (j < ng && (i >= nr || g[j] <= r[i]) && (k >= nb || g[j] <= b[k]))
        j++;
      else
        k++;
    }
    cout << ans << "\n";
  }
}
