#include <bits/stdc++.h>
using namespace std;
long long sq(long long x) { return x * x; }
void f(vector<long long> &a, vector<long long> &b, vector<long long> &c,
       long long &ans) {
  for (auto x : a) {
    auto y = upper_bound(b.begin(), b.end(), x);
    auto z = lower_bound(c.begin(), c.end(), x);
    if (y == b.begin() || z == c.end()) continue;
    y--;
    long long temp = sq(x - *y) + sq(*y - *z) + sq(x - *z);
    if (temp < ans) ans = temp;
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long nr, ng, nb;
    cin >> nr >> ng >> nb;
    vector<long long> r(nr), g(ng), b(nb);
    for (int i = 0; i < nr; i++) cin >> r[i];
    for (int i = 0; i < ng; i++) cin >> g[i];
    for (int i = 0; i < nb; i++) cin >> b[i];
    sort(r.begin(), r.end());
    sort(g.begin(), g.end());
    sort(b.begin(), b.end());
    long long ans = 9e18;
    f(r, g, b, ans);
    f(r, b, g, ans);
    f(g, r, b, ans);
    f(g, b, r, ans);
    f(b, r, g, ans);
    f(b, g, r, ans);
    cout << ans << endl;
  }
}
