#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long llinf = 3000000000000000000ll;
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  a %= b;
  return gcd(b, a);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
bool isPrime(long long num) {
  long long n = num;
  if (n <= 1)
    return false;
  else if (n == 2)
    return true;
  long long prime = 1;
  for (int i = 2; i <= sqrt(abs(n)); i++) {
    if (n % i == 0) {
      prime = 0;
      break;
    }
  }
  return (prime ? true : false);
}
void setIO(string name) {
  freopen(("./codeforces/" + name + ".in").c_str(), "r", stdin);
  freopen(("./codeforces/" + name + ".out").c_str(), "w", stdout);
}
const int mxN = 100005, M = 1e9 + 7;
int tt, nr, ng, nb;
long long r[mxN], g[mxN], b[mxN], ans = llinf;
long long calc(long long rr, long long gg, long long bb) {
  long long x = (gg - rr) * (gg - rr), y = (bb - rr) * (bb - rr),
            z = (bb - gg) * (bb - gg);
  return x + y + z;
}
void f(int nx, int ny, int nz, long long x[], long long y[], long long z[]) {
  long long xx, yy, zz, res;
  for (int i = 0; i < ny; i++) {
    xx = *lower_bound(x, x + nx, y[i]);
    zz = *(upper_bound(z, z + nz, y[i]) - 1);
    if (zz != z[0]) zz = *(upper_bound(z, z + nz, y[i]) - 1);
    if (xx != 0 && zz != 0) {
      ans = min(ans, calc(y[i], xx, zz));
    }
    xx = *upper_bound(x, x + nx, y[i]);
    if (xx != x[0]) xx = *(upper_bound(x, x + nx, y[i]) - 1);
    zz = *lower_bound(z, z + nz, y[i]);
    if (xx != 0 && zz != 0) {
      ans = min(ans, calc(y[i], xx, zz));
    }
  }
}
void solve() {
  cin >> nr >> ng >> nb;
  for (int i = (0); i < (nr); ++i) cin >> r[i];
  for (int i = (0); i < (ng); ++i) cin >> g[i];
  for (int i = (0); i < (nb); ++i) cin >> b[i];
  ans = llinf;
  sort(r, r + nr);
  sort(g, g + ng);
  sort(b, b + nb);
  f(ng, nr, nb, g, r, b);
  f(nr, ng, nb, r, g, b);
  f(nr, nb, ng, r, b, g);
  cout << ans << "\n";
  for (int i = (0); i < (nr); ++i) r[i] = 0;
  for (int i = (0); i < (ng); ++i) g[i] = 0;
  for (int i = (0); i < (nb); ++i) b[i] = 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> tt;
  for (int i = (0); i < (tt); ++i) {
    solve();
  }
}
