#include <bits/stdc++.h>
using namespace std;
const long long MAX_N = 1001000;
const long long INF(0x3f3f3f3f3f3f3f3fll);
const long long N = 3e5 + 10;
struct Edge {
  long long nex, to, w;
} edge[N << 1];
long long head[N], tot;
void add_edge(long long u, long long v, long long w) {
  edge[++tot].nex = head[u];
  edge[tot].to = v;
  edge[tot].w = w;
  head[u] = tot;
}
long long n1, n2, n3;
long long a[N], b[N], c[N];
long long get(long long t1, long long t2, long long t3) {
  return (t1 - t2) * (t1 - t2) + (t1 - t3) * (t1 - t3) + (t2 - t3) * (t2 - t3);
}
long long cal(long long *a, long long n1, long long *b, long long n2,
              long long *c, long long n3) {
  long long res = INF;
  for (long long i = 1; i <= n1; i++) {
    long long one = lower_bound(b + 1, b + 1 + n2, a[i]) - b;
    long long two = lower_bound(c + 1, c + 1 + n3, a[i]) - c;
    if (one > n2 || b[one] > a[i]) {
      if (one > 1) --one;
    }
    if (one <= n2 && two <= n3) {
      long long t1 = a[i];
      long long t2 = b[one];
      long long t3 = c[two];
      res = min(res, get(t1, t2, t3));
    }
    one = lower_bound(c + 1, c + 1 + n3, a[i]) - c;
    two = lower_bound(b + 1, b + 1 + n2, a[i]) - b;
    if (one > n3 || c[one] > a[i]) {
      if (one > 1) one--;
    }
    if (one <= n3 & two <= n2) {
      long long t1 = a[i];
      long long t2 = c[one];
      long long t3 = b[two];
      res = min(res, get(t1, t2, t3));
    }
  }
  return res;
}
struct Pair {
  long long cnt;
  long long sum;
  Pair(long long cnt, long long sum) : cnt(cnt), sum(sum) {}
  Pair operator+(const Pair &a) { return Pair(cnt + a.cnt, sum + a.sum); }
};
struct Node {
  long long l, r, cnt;
  long long sum;
} tree[N << 2];
void pushup(long long k) {
  tree[k].cnt = tree[k << 1].cnt + tree[k << 1 | 1].cnt;
  tree[k].sum = tree[k << 1].sum + tree[k << 1 | 1].sum;
}
void build(long long k, long long l, long long r) {
  tree[k].l = l;
  tree[k].r = r;
  tree[k].cnt = tree[k].sum = 0;
  if (l == r) return;
  long long mid = l + r >> 1;
  build(k << 1, l, mid);
  build(k << 1 | 1, mid + 1, r);
}
void update(long long k, long long pos, long long val) {
  if (tree[k].l == tree[k].r) {
    tree[k].cnt++;
    tree[k].sum += val;
    return;
  }
  long long mid = tree[k].l + tree[k].r >> 1;
  if (mid >= pos)
    update(k << 1, pos, val);
  else
    update(k << 1 | 1, pos, val);
  pushup(k);
}
Pair query(long long k, long long l, long long r) {
  if (tree[k].l > r || tree[k].r < l) return Pair(0, 0LL);
  if (tree[k].l >= l && tree[k].r <= r) return Pair(tree[k].cnt, tree[k].sum);
  return query(k << 1, l, r) + query(k << 1 | 1, l, r);
}
long long quick_power_mod(long long a, long long b, long long m) {
  a %= m;
  long long result = 1;
  while (b > 0) {
    if (b & 1) result = (result * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return result;
}
signed main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  build(1, 1, 1000);
  while (t--) {
    build(1, 1, 1000);
    long long ans = INF;
    cin >> n1 >> n2 >> n3;
    for (long long i = 1; i <= n1; i++) cin >> a[i];
    for (long long i = 1; i <= n2; i++) {
      cin >> b[i];
      long long temp1 = quick_power_mod(1000, 1000, 10000007);
    }
    for (long long i = 1; i <= n3; i++) cin >> c[i];
    build(1, 1, 10);
    sort(a + 1, a + 1 + n1);
    sort(b + 1, b + 1 + n2);
    sort(c + 1, c + 1 + n3);
    long long temp = quick_power_mod(1000, 1000, 10000007);
    build(1, 1, 100);
    ans = min(ans, cal(a, n1, c, n3, b, n2));
    ans = min(ans, cal(c, n3, a, n1, b, n2));
    ans = min(ans, cal(b, n2, a, n1, c, n3));
    cout << ans << '\n';
    build(1, 1, 1000);
  }
  build(1, 1, 1000);
  return 0;
}
