#include <bits/stdc++.h>
using namespace std;
const long long INF = 3e18;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};
const int N = 1e5 + 1;
int nr, nb, ng, r[N], g[N], b[N];
long long sqr(int x) { return 1ll * x * x; }
long long Get(int x, int y, int z) {
  return sqr(r[x] - g[y]) + sqr(g[y] - b[z]) + sqr(b[z] - r[x]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    cin >> nr >> ng >> nb;
    for (int i = 1; i <= nr; i++) cin >> r[i];
    for (int i = 1; i <= ng; i++) cin >> g[i];
    for (int i = 1; i <= nb; i++) cin >> b[i];
    sort(r + 1, r + 1 + nr);
    sort(g + 1, g + 1 + ng);
    sort(b + 1, b + 1 + nb);
    long long res = INF;
    for (int i = 1; i <= nr; i++) {
      int cur = r[i];
      int x = upper_bound(g + 1, g + 1 + ng, cur) - g;
      int y = upper_bound(b + 1, b + 1 + nb, cur) - b;
      if (x <= ng) {
        if (y <= nb) res = min(res, Get(i, x, y));
        if (y - 1 > 0) res = min(res, Get(i, x, y - 1));
      }
      if (x - 1 > 0) {
        if (y <= nb) res = min(res, Get(i, x - 1, y));
        if (y - 1 > 0) res = min(res, Get(i, x - 1, y - 1));
      }
    }
    for (int i = 1; i <= ng; i++) {
      int cur = g[i];
      int x = upper_bound(r + 1, r + 1 + nr, cur) - r;
      int y = upper_bound(b + 1, b + 1 + nb, cur) - b;
      if (x <= nr) {
        if (y <= nb) res = min(res, Get(x, i, y));
        if (y - 1 > 0) res = min(res, Get(x, i, y - 1));
      }
      if (x - 1 > 0) {
        if (y <= nb) res = min(res, Get(x - 1, i, y));
        if (y - 1 > 0) res = min(res, Get(x - 1, i, y - 1));
      }
    }
    for (int i = 1; i <= nb; i++) {
      int cur = b[i];
      int x = upper_bound(r + 1, r + 1 + nr, cur) - r;
      int y = upper_bound(g + 1, g + 1 + ng, cur) - g;
      if (x <= nr) {
        if (y <= ng) res = min(res, Get(x, y, i));
        if (y - 1 > 0) res = min(res, Get(x, y - 1, i));
      }
      if (x - 1 > 0) {
        if (y <= ng) res = min(res, Get(x - 1, y, i));
        if (y - 1 > 0) res = min(res, Get(x - 1, y - 1, i));
      }
    }
    cout << res << '\n';
  }
  return 0;
}
