#include <bits/stdc++.h>
using namespace std;
int nr, ng, nb;
long long red[100005];
long long green[100005];
long long blue[100005];
struct compare {
  bool operator()(const long long& l, const long long& r) const {
    return l > r;
  }
};
bool compare_1(const pair<long long, pair<long long, long long>>& l,
               const pair<long long, pair<long long, long long>>& r) {
  return l.first > r.first;
}
set<long long> l_r, l_g, l_b;
set<long long, compare> s_r, s_g, s_b;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d %d", &nr, &ng, &nb);
    l_r.clear();
    l_g.clear();
    l_b.clear();
    s_r.clear();
    s_g.clear();
    s_b.clear();
    for (int i = 0; i < nr; ++i) {
      scanf("%lld", red + i);
      l_r.insert(red[i]);
      s_r.insert(red[i]);
    }
    for (int i = 0; i < ng; ++i) {
      scanf("%lld", green + i);
      l_g.insert(green[i]);
      s_g.insert(green[i]);
    }
    for (int i = 0; i < nb; ++i) {
      scanf("%lld", blue + i);
      l_b.insert(blue[i]);
      s_b.insert(blue[i]);
    }
    priority_queue<pair<long long, pair<long long, long long>>,
                   vector<pair<long long, pair<long long, long long>>>,
                   decltype(&compare_1)>
        pq(compare_1);
    for (int i = 0; i < nr; ++i) {
      auto tmp = l_g.lower_bound(red[i]);
      if (tmp != l_g.end()) {
        pq.push(
            make_pair((pow(red[i] - *tmp, 2)), (make_pair((red[i]), (*tmp)))));
        if (*tmp == red[i]) continue;
      }
      tmp = s_g.lower_bound(red[i]);
      if (tmp != s_g.end()) {
        pq.push(
            make_pair((pow(red[i] - *tmp, 2)), (make_pair((red[i]), (*tmp)))));
      }
    }
    long long ans = 1ll << 62;
    while (pq.size()) {
      auto m = pq.top();
      pq.pop();
      long long mid = (m.second.first + m.second.second) / 2;
      long long x = m.second.second, y = m.second.first;
      if (x > y) swap(x, y);
      long long minn = m.first + pow(m.second.second - mid, 2) +
                       pow(m.second.first - mid, 2);
      if (minn > ans) break;
      bool in_between = 0;
      auto tmp = l_b.lower_bound(mid);
      if (tmp != l_b.end()) {
        long long z = *tmp;
        if (z >= x && z <= y) {
          in_between = 1;
        }
        long long dist = (long long)(m.first + pow(z - x, 2) + pow(z - y, 2));
        ans = min(ans, dist);
      }
      tmp = s_b.lower_bound(mid);
      if (tmp != s_b.end()) {
        long long z = *tmp;
        if (z >= x && z <= y) {
          in_between = 1;
        }
        long long dist = (long long)(m.first + pow(z - x, 2) + pow(z - y, 2));
        ans = min(ans, dist);
      }
    }
    for (int i = 0; i < nr; ++i) {
      auto tmp = l_b.lower_bound(red[i]);
      if (tmp != l_b.end()) {
        pq.push(
            make_pair((pow(red[i] - *tmp, 2)), (make_pair((red[i]), (*tmp)))));
        if (*tmp == red[i]) continue;
      }
      tmp = s_b.lower_bound(red[i]);
      if (tmp != s_b.end()) {
        pq.push(
            make_pair((pow(red[i] - *tmp, 2)), (make_pair((red[i]), (*tmp)))));
      }
    }
    while (pq.size()) {
      auto m = pq.top();
      pq.pop();
      long long mid = (m.second.first + m.second.second) / 2;
      long long x = m.second.second, y = m.second.first;
      if (x > y) swap(x, y);
      long long minn = m.first + pow(m.second.second - mid, 2) +
                       pow(m.second.first - mid, 2);
      if (minn > ans) break;
      bool in_between = 0;
      auto tmp = l_g.lower_bound(mid);
      if (tmp != l_g.end()) {
        long long z = *tmp;
        if (z >= x && z <= y) {
          in_between = 1;
        }
        long long dist = (long long)(m.first + pow(z - x, 2) + pow(z - y, 2));
        ans = min(ans, dist);
      }
      tmp = s_g.lower_bound(mid);
      if (tmp != s_g.end()) {
        long long z = *tmp;
        if (z >= x && z <= y) {
          in_between = 1;
        }
        long long dist = (long long)(m.first + pow(z - x, 2) + pow(z - y, 2));
        ans = min(ans, dist);
      }
    }
    printf("%lld\n", ans);
  }
}
