#include <bits/stdc++.h>
using namespace std;
long long a[100010], b[100010], c[100010];
int main() {
  int t;
  int x, y, z;
  int id;
  long long ans, t1, t2, t3, res;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d%d", &x, &y, &z);
    for (int i = 1; i <= x; ++i) scanf("%lld", &a[i]);
    for (int i = 1; i <= y; ++i) scanf("%lld", &b[i]);
    for (int i = 1; i <= z; ++i) scanf("%lld", &c[i]);
    sort(a + 1, a + 1 + x);
    sort(b + 1, b + 1 + y);
    sort(c + 1, c + 1 + z);
    ans = -1;
    for (int i = 1; i <= x; ++i) {
      t1 = a[i];
      id = lower_bound(b + 1, b + 1 + y, t1) - b;
      if (id <= y) {
        t2 = b[id];
        id = upper_bound(c + 1, c + 1 + z, t2) - c - 1;
        if (id) {
          t3 = c[id];
          res = (t1 - t2) * (t1 - t2) + (t1 - t3) * (t1 - t3) +
                (t2 - t3) * (t2 - t3);
          if (ans == -1)
            ans = res;
          else
            ans = min(res, ans);
        }
      }
      id = lower_bound(c + 1, c + 1 + z, t1) - c;
      if (id <= z) {
        t2 = c[id];
        id = upper_bound(b + 1, b + 1 + y, t2) - b - 1;
        if (id) {
          t3 = b[id];
          res = (t1 - t2) * (t1 - t2) + (t1 - t3) * (t1 - t3) +
                (t2 - t3) * (t2 - t3);
          if (ans == -1)
            ans = res;
          else
            ans = min(res, ans);
        }
      }
    }
    for (int i = 1; i <= y; ++i) {
      t1 = b[i];
      id = lower_bound(a + 1, a + 1 + x, t1) - a;
      if (id <= x) {
        t2 = a[id];
        id = upper_bound(c + 1, c + 1 + z, t2) - c - 1;
        if (id) {
          t3 = c[id];
          res = (t1 - t2) * (t1 - t2) + (t1 - t3) * (t1 - t3) +
                (t2 - t3) * (t2 - t3);
          if (ans == -1)
            ans = res;
          else
            ans = min(res, ans);
        }
      }
      id = lower_bound(c + 1, c + 1 + z, t1) - c;
      if (id <= z) {
        t2 = c[id];
        id = upper_bound(a + 1, a + 1 + x, t2) - a - 1;
        if (id) {
          t3 = a[id];
          res = (t1 - t2) * (t1 - t2) + (t1 - t3) * (t1 - t3) +
                (t2 - t3) * (t2 - t3);
          if (ans == -1)
            ans = res;
          else
            ans = min(res, ans);
        }
      }
    }
    for (int i = 1; i <= z; ++i) {
      t1 = c[i];
      id = lower_bound(a + 1, a + 1 + x, t1) - a;
      if (id <= x) {
        t2 = a[id];
        id = upper_bound(b + 1, b + 1 + y, t2) - b - 1;
        if (id) {
          t3 = b[id];
          res = (t1 - t2) * (t1 - t2) + (t1 - t3) * (t1 - t3) +
                (t2 - t3) * (t2 - t3);
          if (ans == -1)
            ans = res;
          else
            ans = min(res, ans);
        }
      }
      id = lower_bound(b + 1, b + 1 + y, t1) - b;
      if (id <= y) {
        t2 = b[id];
        id = upper_bound(a + 1, a + 1 + x, t2) - a - 1;
        if (id) {
          t3 = a[id];
          res = (t1 - t2) * (t1 - t2) + (t1 - t3) * (t1 - t3) +
                (t2 - t3) * (t2 - t3);
          if (ans == -1)
            ans = res;
          else
            ans = min(res, ans);
        }
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
