30 30 10
6 1
8 27
5 1
21 6
24 15
12 5
29 7
22 7
23 17
2 13
23 11
29 6
14 18
29 16
27 25
15 2
27 4
19 30
28 19
17 2
27 16
3 4
9 25
19 16
10 16
18 17
26 11
2 27
16 20
13 23
1 4
27 7
6 20
17 30
1 18
2 17
1 11
5 9
25 13
11 20
14 25
30 21
6 24
12 2
25 12
22 13
10 27
24 29
19 24
28 29
24 23
9 6
12 15
11 15
23 14
12 28
28 25
2 11
19 30
 2 2 1
1 2
2 1
1 2

0 1
#include <bits/stdc++.h>
using namespace std;
long long nr, ng, nb;
long long r[200000], g[200000], b[200000];
long long gr(long long val) {
  long long ans = -1;
  long long l1 = 0, r1 = nr - 1;
  while (l1 <= r1) {
    long long mid = (l1 + r1) >> 1;
    if (r[mid] >= val) {
      ans = r[mid];
      r1 = mid - 1;
    } else
      l1 = mid + 1;
  }
  return ans;
}
long long lr(long long val) {
  long long ans = -1;
  long long l1 = 0, r1 = nr - 1;
  while (l1 <= r1) {
    long long mid = (l1 + r1) >> 1;
    if (r[mid] <= val) {
      ans = r[mid];
      l1 = mid + 1;
    } else
      r1 = mid - 1;
  }
  return ans;
}
long long gg(long long val) {
  long long ans = -1;
  long long l1 = 0, r1 = ng - 1;
  while (l1 <= r1) {
    long long mid = (l1 + r1) >> 1;
    if (g[mid] >= val) {
      ans = g[mid];
      r1 = mid - 1;
    } else
      l1 = mid + 1;
  }
  return ans;
}
long long lg(long long val) {
  long long ans = -1;
  long long l1 = 0, r1 = ng - 1;
  while (l1 <= r1) {
    long long mid = (l1 + r1) >> 1;
    if (g[mid] <= val) {
      ans = g[mid];
      l1 = mid + 1;
    } else
      r1 = mid - 1;
  }
  return ans;
}
long long gb(long long val) {
  long long ans = -1;
  long long l1 = 0, r1 = ng - 1;
  while (l1 <= r1) {
    long long mid = (l1 + r1) >> 1;
    if (b[mid] >= val) {
      ans = b[mid];
      r1 = mid - 1;
    } else
      l1 = mid + 1;
  }
  return ans;
}
long long lb(long long val) {
  long long ans = -1;
  long long l1 = 0, r1 = nb - 1;
  while (l1 <= r1) {
    long long mid = (l1 + r1) >> 1;
    if (b[mid] <= val) {
      ans = b[mid];
      l1 = mid + 1;
    } else
      r1 = mid - 1;
  }
  return ans;
}
void solv() {
  cin >> nr >> ng >> nb;
  for (long long i = 0; i < nr; i++) cin >> r[i];
  for (long long i = 0; i < ng; i++) cin >> g[i];
  for (long long i = 0; i < nb; i++) cin >> b[i];
  sort(r, r + nr);
  sort(g, g + ng);
  sort(b, b + nb);
  long long ans = 2000000000000000000;
  for (long long i = 0; i < nr; i++) {
    long long x, y, z;
    x = r[i], y = gg(r[i]), z = lb(r[i]);
    if (y != -1 and z != -1) {
      ans = min(ans, (x - y) * (x - y) + (y - z) * (y - z) + (x - z) * (x - z));
    }
    y = lg(r[i]), z = gb(r[i]);
    if (y != -1 and z != -1) {
      ans = min(ans, (x - y) * (x - y) + (y - z) * (y - z) + (x - z) * (x - z));
    }
  }
  for (long long i = 0; i < nb; i++) {
    long long x, y, z;
    x = b[i], y = gg(b[i]), z = lr(b[i]);
    if (y != -1 and z != -1) {
      ans = min(ans, (x - y) * (x - y) + (y - z) * (y - z) + (x - z) * (x - z));
    }
    y = lg(b[i]), z = gr(b[i]);
    if (y != -1 and z != -1) {
      ans = min(ans, (x - y) * (x - y) + (y - z) * (y - z) + (x - z) * (x - z));
    }
  }
  for (long long i = 0; i < ng; i++) {
    long long x, y, z;
    x = g[i], y = gr(g[i]), z = lb(g[i]);
    if (y != -1 and z != -1) {
      ans = min(ans, (x - y) * (x - y) + (y - z) * (y - z) + (x - z) * (x - z));
    }
    y = lr(g[i]), z = gb(g[i]);
    if (y != -1 and z != -1) {
      ans = min(ans, (x - y) * (x - y) + (y - z) * (y - z) + (x - z) * (x - z));
    }
  }
  cout << ans << '\n';
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  long long t;
  cin >> t;
  while (t--) solv();
}
