#include <bits/stdc++.h>
using namespace std;
const int N = 10000001;
int t;
long long a[N], b[N], c[N];
int x, y, z;
long long find(long long x, long long y, long long z) {
  return (x - y) * (x - y) + (x - z) * (x - z) + (y - z) * (y - z);
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d %d", &x, &y, &z);
    for (int i = 0; i < x; i++) scanf("%lld", &a[i]);
    for (int i = 0; i < y; i++) scanf("%lld", &b[i]);
    for (int i = 0; i < z; i++) scanf("%lld", &c[i]);
    sort(a, a + x);
    sort(b, b + y);
    sort(c, c + z);
    long long ans = 4e18;
    for (int i = 0; i < x; i++) {
      int xx = lower_bound(b, b + y, a[i]) - b;
      int yy = lower_bound(c, c + z, a[i]) - c;
      if (xx == y) xx--;
      if (yy == z) yy--;
      if (xx > 0) ans = min(ans, find(a[i], b[xx - 1], c[yy]));
      if (yy > 0) ans = min(ans, find(a[i], b[xx], c[yy - 1]));
      ans = min(ans, find(a[i], b[xx], c[yy]));
    }
    for (int i = 0; i < y; i++) {
      int xx = lower_bound(a, a + x, b[i]) - a;
      int yy = lower_bound(c, c + z, b[i]) - c;
      if (xx == x) xx--;
      if (yy == z) yy--;
      if (xx > 0) ans = min(ans, find(a[xx - 1], b[i], c[yy]));
      if (yy > 0) ans = min(ans, find(a[xx], b[i], c[yy - 1]));
      ans = min(ans, find(a[xx], b[i], c[yy]));
    }
    for (int i = 0; i < z; i++) {
      int xx = lower_bound(a, a + x, c[i]) - a;
      int yy = lower_bound(b, b + y, c[i]) - b;
      if (xx == x) xx--;
      if (yy == y) yy--;
      if (xx > 0) ans = min(ans, find(a[xx - 1], b[yy], c[i]));
      if (yy > 0) ans = min(ans, find(a[xx], b[yy - 1], c[i]));
      ans = min(ans, find(a[xx], b[yy], c[i]));
    }
    cout << ans << endl;
  }
}
