#include <bits/stdc++.h>
const int N = 100001;
using namespace std;
long long int f(vector<long long int> &a, vector<long long int> &b,
                vector<long long int> &c) {
  long long int ans = LONG_LONG_MAX;
  for (long long int x : a) {
    auto it = lower_bound(c.begin(), c.end(), x);
    if (it != c.end()) {
      long long int tar = (x + *it) / 2;
      int lft = upper_bound(b.begin(), b.end(), tar) - b.begin() - 1;
      int rht = lower_bound(b.begin(), b.end(), tar) - b.begin();
      if (lft >= 0) {
        long long int val = (x - b[lft]) * (x - b[lft]) +
                            (b[lft] - *it) * (b[lft] - *it) +
                            (*it - x) * (*it - x);
        ans = min(ans, val);
      }
      if (rht < b.size()) {
        long long int val = (x - b[rht]) * (x - b[rht]) +
                            (b[rht] - *it) * (b[rht] - *it) +
                            (*it - x) * (*it - x);
        ans = min(ans, val);
      }
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, m, o;
    cin >> n >> m >> o;
    vector<long long int> a(n), b(m), c(o);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> b[i];
    }
    for (int i = 0; i < o; i++) {
      cin >> c[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    cout << min({f(a, b, c), f(a, c, b), f(b, a, c), f(b, c, a), f(c, a, b),
                 f(c, b, a)})
         << '\n';
  }
}
