#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793238462643383;
const long long mod = 1000000007;
int Ceil(int a, int b) {
  if (a % b == 0)
    return a / b;
  else
    return (a / b) + 1;
}
long long calc(long long r, long long g, long long b) {
  return (r - g) * (r - g) + (r - b) * (r - b) + (g - b) * (g - b);
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  int t;
  cin >> t;
  while (t--) {
    vector<vector<long long>> v;
    int nr, ng, nb;
    cin >> nr >> ng >> nb;
    vector<long long> r(nr);
    vector<long long> g(ng);
    vector<long long> b(nb);
    for (int i = 0; i < nr; i++) cin >> r[i];
    sort(r.begin(), r.end());
    v.push_back(r);
    for (int i = 0; i < ng; i++) cin >> g[i];
    sort(g.begin(), g.end());
    v.push_back(g);
    for (int i = 0; i < nb; i++) cin >> b[i];
    sort(b.begin(), b.end());
    v.push_back(b);
    long long ans = -1;
    for (int l = 0; l < 3; l++) {
      for (int m = 0; m < 3; m++) {
        for (int r = 0; r < 3; r++) {
          if (l == m || l == r || m == r) continue;
          for (int j = 0; j < v[m].size(); j++) {
            int i = upper_bound(v[l].begin(), v[l].end(), v[m][j]) -
                    v[l].begin() - 1;
            int k =
                lower_bound(v[r].begin(), v[r].end(), v[m][j]) - v[r].begin();
            if (i != -1 && k != v[r].size()) {
              if (ans == -1)
                ans = calc(v[l][i], v[m][j], v[r][k]);
              else
                ans = min(ans, calc(v[l][i], v[m][j], v[r][k]));
            }
          }
        }
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
