#include <bits/stdc++.h>
using namespace std;
inline int add(int a, int b) {
  a += b;
  return a >= 1000000007 ? a - 1000000007 : a;
}
inline int sub(int a, int b) {
  a -= b;
  return a < 0 ? a + 1000000007 : a;
}
inline int mul(int a, int b) { return (long long int)a * b % 1000000007; }
int Set(int N, int pos) { return N = N | (1 << pos); }
int Reset(int N, int pos) { return N = N & ~(1 << pos); }
bool Cheek(int N, int pos) { return (bool)(N & (1 << pos)); }
long long int Small(vector<long long int>& v, long long int ITEM) {
  long long int lo = 0, hi = (long long int)v.size() - 1, mid, res = v[0];
  while (lo <= hi) {
    mid = (lo + hi) >> 1;
    if (v[mid] <= ITEM) {
      res = v[mid];
      lo = mid + 1;
    } else
      hi = mid - 1;
  }
  return res;
}
long long int Big(vector<long long int>& v, long long int ITEM) {
  long long int lo = 0, hi = (long long int)v.size() - 1, mid, res = v.back();
  while (lo <= hi) {
    mid = (lo + hi) >> 1;
    if (v[mid] >= ITEM) {
      res = v[mid];
      hi = mid - 1;
    } else
      lo = mid + 1;
  }
  return res;
}
long long int Calc(long long int x, long long int y, long long int z) {
  return ((long long int)((x - y) * (x - y)) +
          ((long long int)(y - z) * (y - z)) +
          ((long long int)(z - x) * (z - x)));
}
long long int Call(vector<long long int>& v1, vector<long long int>& v2,
                   vector<long long int>& v3) {
  long long int x, y, z, temp, ans = 1LL << 62LL;
  for (long long int i = 0; i < (long long int)v1.size(); i++) {
    y = v1[i];
    x = Small(v2, y);
    z = Small(v3, y);
    temp = Calc(x, y, z);
    ans = min(ans, temp);
    x = Small(v2, y);
    z = Big(v3, y);
    temp = Calc(x, y, z);
    ans = min(ans, temp);
    x = Big(v2, y);
    z = Small(v3, y);
    temp = Calc(x, y, z);
    ans = min(ans, temp);
    x = Big(v2, y);
    z = Big(v3, y);
    temp = Calc(x, y, z);
    ans = min(ans, temp);
  }
  return ans;
}
void Solve(int t) {
  vector<long long int> red, green, blue;
  long long int i, j, k, ans = 1LL << 62, nr, ng, nb, x, y, z, temp;
  scanf("%lld %lld %lld", &nr, &ng, &nb);
  for (__typeof(i) i = 1; i <= nr; i++) {
    scanf("%lld", &(temp));
    red.push_back(temp);
  }
  for (__typeof(i) i = 1; i <= ng; i++) {
    scanf("%lld", &(temp));
    green.push_back(temp);
  }
  for (__typeof(i) i = 1; i <= nb; i++) {
    scanf("%lld", &(temp));
    blue.push_back(temp);
  }
  sort(red.begin(), red.end());
  sort(green.begin(), green.end());
  sort(blue.begin(), blue.end());
  ans = min(ans, Call(red, green, blue));
  ans = min(ans, Call(green, red, blue));
  ans = min(ans, Call(blue, red, green));
  cout << ans << endl;
}
int main() {
  int t, T;
  scanf("%d", &(T));
  for (__typeof(t) t = 1; t <= T; t++) {
    Solve(t);
  }
  return 0;
}
