#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
istream &operator>>(istream &in, pair<T, U> &rhs) {
  in >> rhs.first;
  in >> rhs.second;
  return in;
}
template <class T, class U>
ostream &operator<<(ostream &out, const pair<T, U> &rhs) {
  out << rhs.first;
  out << " ";
  out << rhs.second;
  return out;
}
template <class T, class U>
pair<T, U> operator+(pair<T, U> &a, pair<T, U> &b) {
  return pair<T, U>(a.first + b.first, a.second + b.second);
}
template <class T, class U>
pair<T, U> operator-(pair<T, U> &a, pair<T, U> &b) {
  return pair<T, U>(a.first - b.first, a.second - b.second);
}
template <class T>
istream &operator>>(istream &in, vector<T> &a) {
  for (auto &i : a) cin >> i;
  return in;
}
template <class T>
ostream &operator<<(ostream &out, const vector<T> &a) {
  for (auto &i : a) cout << i << " ";
  return out;
}
template <class T>
ostream &operator<<(ostream &out, const set<T> &a) {
  for (auto &i : a) cout << i << " ";
  return out;
}
template <class T>
ostream &operator<<(ostream &out, const unordered_set<T> &a) {
  for (auto &i : a) cout << i << " ";
  return out;
}
template <class T>
ostream &operator<<(ostream &out, const multiset<T> &a) {
  for (auto &i : a) cout << i << " ";
  return out;
}
template <class T, class U>
ostream &operator<<(ostream &out, const map<T, U> &a) {
  for (auto &i : a) cout << "(" << i.first << ", " << i.second << "(\n";
  return out;
}
template <class T, class U>
ostream &operator<<(ostream &out, const unordered_map<T, U> &a) {
  for (auto &i : a) cout << "(" << i.first << ", " << i.second << "(\n";
  return out;
}
void judge() {}
long long check(long long a, long long b, long long c) {
  long long x = a - b;
  long long y = b - c;
  long long z = a - c;
  long long ans = (x * x) + (y * y) + (z * z);
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  ;
  long long t = 1;
  judge();
  cin >> t;
  for (int h = 0; h < t; h++) {
    long long m, n, o;
    cin >> m >> n >> o;
    vector<long long> r(m), g(n), b(o);
    cin >> r >> g >> b;
    sort(r.begin(), r.end());
    sort(g.begin(), g.end());
    sort(b.begin(), b.end());
    long long i = 0, j = 0, k = 0;
    long long ans = 4e18;
    while (i < m && j < n && k < o) {
      long long v1 = r[i];
      long long v2 = g[j];
      long long v3 = b[k];
      ans = min(ans, check(v1, v2, v3));
      if (i - 1 >= 0) ans = min(ans, check(r[i - 1], v2, v3));
      if (j - 1 >= 0) ans = min(ans, check(v1, g[j - 1], v3));
      if (k - 1 >= 0) ans = min(ans, check(v1, v2, b[k - 1]));
      vector<long long> v;
      v.push_back(v1);
      v.push_back(v2);
      v.push_back(v3);
      sort(v.begin(), v.end());
      long long pi = i, pj = j, pk = k;
      if (v1 == v[0] && i < m - 1)
        i++;
      else if (v2 == v[0] && j < n - 1)
        j++;
      else if (v3 == v[0] && k < o - 1)
        k++;
      else {
        if (v1 == v[1] && i < m - 1)
          i++;
        else if (v2 == v[1] && j < n - 1)
          j++;
        else if (v3 == v[1] && k < o - 1)
          k++;
        else {
          break;
        }
      }
    }
    cout << ans << endl;
  }
}
