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