#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= f;
}
template <class T>
T gcd(T a, T b) {
  return !b ? a : gcd(b, a % b);
}
template <class T>
inline void umin(T &x, T y) {
  x = x < y ? x : y;
}
template <class T>
inline void umax(T &x, T y) {
  x = x > y ? x : y;
}
mt19937 R(chrono::system_clock().now().time_since_epoch().count());
const int N = 666666;
long long res;
long long ff(long long x) { return x * x; }
long long solve(vector<int> a, vector<int> b, vector<int> c) {
  for (int x : b) {
    bool gg = 0;
    int y = lower_bound(c.begin(), c.end(), x) - c.begin();
    if (y < ((int)c.size()))
      y = c[y];
    else
      gg = 1;
    int z = upper_bound(a.begin(), a.end(), x) - a.begin();
    if (!z)
      gg = 1;
    else
      z = a[z - 1];
    if (!gg) umin(res, ff(z - x) + ff(z - y) + ff(y - x));
  }
  return 8e18;
}
int main() {
  int T;
  read(T);
  while (T--) {
    int n1, n2, n3;
    read(n1);
    read(n2);
    read(n3);
    vector<int> a, b, c;
    int x;
    while (n1--) read(x), a.push_back(x);
    while (n2--) read(x), b.push_back(x);
    while (n3--) read(x), c.push_back(x);
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    res = 8e18;
    umin(res, solve(a, b, c));
    umin(res, solve(a, c, b));
    umin(res, solve(b, a, c));
    umin(res, solve(b, c, a));
    umin(res, solve(c, a, b));
    umin(res, solve(c, b, a));
    printf("%lld\n", res);
  }
  return 0;
}
