#include <bits/stdc++.h>
using namespace std;
long long POW(long long a, long long n) {
  if (n == 0) return 1;
  if (n % 2 == 0) {
    long long res = POW(a, n / 2);
    return res * res;
  } else
    return a * POW(a, n - 1);
}
long long gcd(long long a, long long b) {
  while (a != 0 && b != 0) {
    if (a > b)
      a %= b;
    else
      b %= a;
  }
  return max(a, b);
}
int bin_search(vector<long long> &arr, long long x) {
  int l = 1, r = arr.size() - 1;
  while (l < r) {
    int mid = (l + r) / 2;
    if (arr[mid] > x)
      r = mid;
    else
      l = mid + 1;
  }
  return l;
}
vector<long long> r;
vector<long long> g;
vector<long long> b;
long long calc(int i, int j, int k) {
  return (r[i] - g[j]) * (r[i] - g[j]) + (r[i] - b[k]) * (r[i] - b[k]) +
         (g[j] - b[k]) * (g[j] - b[k]);
}
int main() {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base ::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int nr, ng, nb;
    cin >> nr >> ng >> nb;
    set<long long> st1;
    set<long long> st2;
    set<long long> st3;
    long long x;
    for (int i = 1; i <= nr; i++) {
      cin >> x;
      st1.insert(x);
    }
    for (int i = 1; i <= ng; i++) {
      cin >> x;
      st2.insert(x);
    }
    for (int i = 1; i <= nb; i++) {
      cin >> x;
      st3.insert(x);
    }
    r.resize(1);
    g.resize(1);
    b.resize(1);
    for (set<long long>::iterator it = st1.begin(); it != st1.end(); it++)
      r.push_back((*it));
    for (set<long long>::iterator it = st2.begin(); it != st2.end(); it++)
      g.push_back((*it));
    for (set<long long>::iterator it = st3.begin(); it != st3.end(); it++)
      b.push_back((*it));
    long long ans = 8e18;
    int iter = 1;
    nr = st1.size();
    ng = st2.size();
    nb = st3.size();
    for (int i = 1; i <= nr; i++) {
      while (iter <= ng && g[iter] <= r[i]) iter++;
      iter--;
      if (iter == 0 || iter == ng) {
        if (iter == 0) iter = 1;
        long long m = (r[i] + g[iter]) / 2;
        int it = bin_search(b, m);
        if (it == 1)
          ans = min(ans, calc(i, iter, it));
        else {
          ans = min(ans, calc(i, iter, it));
          ans = min(ans, calc(i, iter, it - 1));
        }
        if (iter != 1) {
          long long m3 = (r[i] + g[iter - 1]) / 2;
          it = bin_search(b, m3);
          if (it == 1)
            ans = min(ans, calc(i, iter - 1, it));
          else {
            ans = min(ans, calc(i, iter - 1, it));
            ans = min(ans, calc(i, iter - 1, it - 1));
          }
        }
      } else {
        long long m1 = (r[i] + g[iter]) / 2;
        long long m2 = (r[i] + g[iter + 1]) / 2;
        int it = bin_search(b, m1);
        if (it == 1)
          ans = min(ans, calc(i, iter, it));
        else {
          ans = min(ans, calc(i, iter, it));
          ans = min(ans, calc(i, iter, it - 1));
        }
        it = bin_search(b, m2);
        if (it == 1)
          ans = min(ans, calc(i, iter + 1, it));
        else {
          ans = min(ans, calc(i, iter + 1, it));
          ans = min(ans, calc(i, iter + 1, it - 1));
        }
        if (iter != 1) {
          long long m3 = (r[i] + g[iter - 1]) / 2;
          it = bin_search(b, m3);
          if (it == 1)
            ans = min(ans, calc(i, iter - 1, it));
          else {
            ans = min(ans, calc(i, iter - 1, it));
            ans = min(ans, calc(i, iter - 1, it - 1));
          }
        }
      }
    }
    iter = 1;
    for (int i = 1; i <= nr; i++) {
      while (iter <= nb && b[iter] <= r[i]) iter++;
      iter--;
      if (iter == 0 || iter == nb) {
        if (iter == 0) iter = 1;
        long long m = (r[i] + b[iter]) / 2;
        int it = bin_search(g, m);
        if (it == 1)
          ans = min(ans, calc(i, it, iter));
        else {
          ans = min(ans, calc(i, it, iter));
          ans = min(ans, calc(i, it - 1, iter));
        }
        if (iter != 1) {
          long long m3 = (r[i] + b[iter - 1]) / 2;
          it = bin_search(g, m3);
          if (it == 1)
            ans = min(ans, calc(i, it, iter - 1));
          else {
            ans = min(ans, calc(i, it, iter - 1));
            ans = min(ans, calc(i, it - 1, iter - 1));
          }
        }
      } else {
        long long m1 = (r[i] + b[iter]) / 2;
        long long m2 = (r[i] + b[iter + 1]) / 2;
        int it = bin_search(g, m1);
        if (it == 1)
          ans = min(ans, calc(i, it, iter));
        else {
          ans = min(ans, calc(i, it, iter));
          ans = min(ans, calc(i, it - 1, iter));
        }
        it = bin_search(g, m2);
        if (it == 1)
          ans = min(ans, calc(i, it, iter + 1));
        else {
          ans = min(ans, calc(i, it, iter + 1));
          ans = min(ans, calc(i, it - 1, iter + 1));
        }
        if (iter != 1) {
          long long m3 = (r[i] + b[iter - 1]) / 2;
          it = bin_search(g, m3);
          if (it == 1)
            ans = min(ans, calc(i, it, iter - 1));
          else {
            ans = min(ans, calc(i, it, iter - 1));
            ans = min(ans, calc(i, it - 1, iter - 1));
          }
        }
      }
    }
    iter = 1;
    for (int i = 1; i <= nb; i++) {
      while (iter <= ng && g[iter] <= b[i]) iter++;
      iter--;
      if (iter == 0 || iter == ng) {
        if (iter == 0) iter = 1;
        long long m = (b[i] + g[iter]) / 2;
        int it = bin_search(r, m);
        if (it == 1)
          ans = min(ans, calc(it, iter, i));
        else {
          ans = min(ans, calc(it, iter, i));
          ans = min(ans, calc(it - 1, iter, i));
        }
        if (iter != 1) {
          long long m3 = (b[i] + g[iter - 1]) / 2;
          it = bin_search(r, m3);
          if (it == 1)
            ans = min(ans, calc(it, iter - 1, i));
          else {
            ans = min(ans, calc(it, iter - 1, i));
            ans = min(ans, calc(it - 1, iter - 1, i));
          }
        }
      } else {
        long long m1 = (b[i] + g[iter]) / 2;
        long long m2 = (b[i] + g[iter + 1]) / 2;
        int it = bin_search(r, m1);
        if (it == 1)
          ans = min(ans, calc(it, iter, i));
        else {
          ans = min(ans, calc(it, iter, i));
          ans = min(ans, calc(it - 1, iter, i));
        }
        it = bin_search(r, m2);
        if (it == 1)
          ans = min(ans, calc(it, iter + 1, i));
        else {
          ans = min(ans, calc(it, iter + 1, i));
          ans = min(ans, calc(it - 1, iter + 1, i));
        }
        if (iter != 1) {
          long long m3 = (b[i] + g[iter - 1]) / 2;
          it = bin_search(r, m3);
          if (it == 1)
            ans = min(ans, calc(it, iter - 1, i));
          else {
            ans = min(ans, calc(it, iter - 1, i));
            ans = min(ans, calc(it - 1, iter - 1, i));
          }
        }
      }
    }
    cout << ans << '\n';
  }
}
