#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long pows(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long powm(long long x, long long y, long long m = 1000000007) {
  x = x % m;
  long long res = 1;
  while (y) {
    if (y & 1) res = res * x;
    res %= m;
    y = y >> 1;
    x = x * x;
    x %= m;
  }
  return res;
}
long long modInverse(long long a, long long m = 1000000007) {
  if (m == 1) return 0;
  long long m0 = m, y = 0, x = 1;
  while (a > 1) {
    long long q = a / m, t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
long long fa = 9e18;
void calc(set<long long> st1, set<long long> st2, set<long long> st3) {
  for (auto i : st1) {
    long long x = i;
    auto it1 = st2.lower_bound(x);
    set<long long> gr, bl;
    if (it1 != st2.end()) {
      gr.insert(*it1);
    }
    if (it1 != st2.begin()) {
      it1--;
      gr.insert(*it1);
    }
    auto it2 = st2.upper_bound(x);
    if (it2 != st2.end()) {
      gr.insert(*it2);
    }
    it1 = st3.lower_bound(x);
    if (it1 != st3.end()) {
      bl.insert(*it1);
    }
    if (it1 != st3.begin()) {
      it1--;
      bl.insert(*it1);
    }
    it2 = st3.upper_bound(x);
    if (it2 != st3.end()) {
      bl.insert(*it2);
    }
    for (auto j : gr) {
      it1 = st3.lower_bound(j);
      if (it1 != st3.end()) {
        bl.insert(*it1);
      }
      if (it1 != st3.begin()) {
        it1--;
        bl.insert(*it1);
      }
      it2 = st3.upper_bound(j);
      if (it2 != st3.end()) {
        bl.insert(*it2);
      }
    }
    if (gr.size() > 0 && bl.size() > 0) {
      for (auto j : gr) {
        for (auto k : bl) {
          long long p =
              (x - j) * (x - j) + (j - k) * (j - k) + (k - x) * (k - x);
          fa = min(fa, p);
        }
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long T;
  cin >> T;
  while (T--) {
    long long n, m, i, j, k, x, y, z, t, e, f, p, q, g, l, r, w, h,
        count1 = 0, prod = 1, a, b, c, d, index, x1, x2, y1, y2, diff, ans = 0,
        sum = 0, sum1 = 0, sum2 = 0, flag = 0, flag1 = 0, flag2 = 0;
    string s, s1, s2;
    cin >> a >> b >> c;
    fa = 9e18;
    set<long long> red, blue, green;
    for (i = 0; i < a; i++) {
      cin >> x;
      red.insert(x);
    }
    for (i = 0; i < b; i++) {
      cin >> a;
      green.insert(a);
    }
    for (i = 0; i < c; i++) {
      cin >> a;
      blue.insert(a);
    }
    calc(red, green, blue);
    calc(red, blue, green);
    calc(blue, green, red);
    calc(blue, red, green);
    calc(green, red, blue);
    calc(green, blue, red);
    cout << fa << "\n";
  }
}
