#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 3, mod = 1e9 + 7;
long long dis(long long x, long long y, long long z) {
  return (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x);
}
long long solve(vector<long long> &a, vector<long long> &b,
                vector<long long> &c) {
  long long ret = LLONG_MAX;
  for (auto ele : a) {
    vector<long long> v, v2;
    auto it = lower_bound(b.begin(), b.end(), ele);
    if (it != b.end()) v.push_back(*it);
    if (it != b.begin()) v.push_back(*(--it));
    it = lower_bound(c.begin(), c.end(), ele);
    if (it != c.end()) v2.push_back(*it);
    if (it != c.begin()) v2.push_back(*(--it));
    for (auto ele2 : v)
      for (auto ele3 : v2) ret = min(ret, dis(ele, ele2, ele3));
  }
  return ret;
}
void test() {
  int r, g, b;
  cin >> r >> g >> b;
  vector<vector<long long>> arr(3);
  arr[0].resize(r), arr[1].resize(g), arr[2].resize(b);
  for (int i = 0; i < r; i++) cin >> arr[0][i];
  for (int i = 0; i < g; i++) cin >> arr[1][i];
  for (int i = 0; i < b; i++) cin >> arr[2][i];
  long long mn = LLONG_MAX;
  for (auto &ele : arr) sort(ele.begin(), ele.end());
  vector<int> per = {0, 1, 2};
  do {
    mn = min(mn, solve(arr[per[0]], arr[per[1]], arr[per[2]]));
  } while (next_permutation(per.begin(), per.end()));
  printf("%lld\n", mn);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
  cin >> t;
  for (int cas = 1; cas <= t; cas++) {
    test();
  }
}
