#include <bits/stdc++.h>
using namespace std;
unsigned long long solve(vector<long long> rw, vector<long long> bw,
                         vector<long long> gw) {
  unsigned long long min = 3 * (1e18 + 1);
  for (int i = 0; i < rw.size(); i++) {
    long long x = rw[i];
    int yg = lower_bound(gw.begin(), gw.end(), x) - gw.begin();
    if (yg == gw.size())
      yg--;
    else {
      int yl;
      if (yg != 0) {
        yl = yg - 1;
        if (abs(gw[yl] - x) < abs(gw[yg] - x)) {
          yg = yl;
        }
      }
    }
    long long y = gw[yg];
    int zg = lower_bound(bw.begin(), bw.end(), x) - bw.begin();
    if (zg == bw.size())
      zg--;
    else {
      int zl;
      if (zg != 0) {
        zl = zg - 1;
        if (abs(bw[zl] - x) < abs(bw[zg] - x)) {
          zg = zl;
        }
      }
    }
    long long z = bw[zg];
    if ((x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x) < min)
      min = (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x);
  }
  return min;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long r, g, b;
    cin >> r >> g >> b;
    vector<long long> rw(r), gw(g), bw(b);
    for (int i = 0; i < r; i++) cin >> rw[i];
    for (int i = 0; i < g; i++) cin >> gw[i];
    for (int i = 0; i < b; i++) cin >> bw[i];
    sort(rw.begin(), rw.end());
    sort(gw.begin(), gw.end());
    sort(bw.begin(), bw.end());
    unsigned long long m = 3 * (1e18 + 1);
    m = min(m, solve(rw, gw, bw));
    m = min(m, solve(gw, bw, rw));
    m = min(m, solve(bw, rw, gw));
    cout << m << "\n";
  }
  return 0;
}
