#include <bits/stdc++.h>
template <class T>
inline void read(T &x) {
  x = 0;
  int f = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    f |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  x = f ? -x : x;
  return;
}
std::vector<long long> r, g, b;
long long ans, nr, ng, nb, t, p;
void solve(std::vector<long long> a, std::vector<long long> b,
           std::vector<long long> c) {
  for (auto x : a) {
    auto y = std::lower_bound(b.begin(), b.end(), x),
         z = std::upper_bound(c.begin(), c.end(), x);
    if (y == b.end() || z == c.begin()) continue;
    --z;
    ans = std::min(
        ans, (x - *y) * (x - *y) + (*y - *z) * (*y - *z) + (x - *z) * (x - *z));
  }
}
int main() {
  read(t);
  while (t--) {
    ans = 9e18;
    r.clear(), g.clear(), b.clear();
    read(nr), read(ng), read(nb);
    for (int i = 1; i <= nr; ++i) read(p), r.push_back(p);
    for (int i = 1; i <= ng; ++i) read(p), g.push_back(p);
    for (int i = 1; i <= nb; ++i) read(p), b.push_back(p);
    std::sort(r.begin(), r.end()), std::sort(g.begin(), g.end()),
        std::sort(b.begin(), b.end());
    solve(r, g, b), solve(r, b, g), solve(g, r, b), solve(g, b, r),
        solve(b, r, g), solve(b, g, r);
    printf("%lld\n", ans);
  }
  return 0;
}
