#include <bits/stdc++.h>
using namespace std;
long long ans;
void fx(vector<int> r, vector<int> g, vector<int> b) {
  for (auto x : r) {
    vector<int>::iterator y = lower_bound(g.begin(), g.end(), x);
    vector<int>::iterator z = upper_bound(b.begin(), b.end(), x);
    if (y == g.end() || z == b.begin()) continue;
    z--;
    ans = min(ans, 1LL * (x - *y) * (x - *y) + 1LL * (*y - *z) * (*y - *z) +
                       1LL * (*z - x) * (*z - x));
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int r, g, b;
    ans = 9e18;
    cin >> r >> g >> b;
    vector<int> R(r), G(g), B(b);
    for (auto &a : R) cin >> a;
    for (auto &a : G) cin >> a;
    for (auto &a : B) cin >> a;
    sort(R.begin(), R.end());
    sort(G.begin(), G.end());
    sort(B.begin(), B.end());
    fx(R, G, B);
    fx(R, B, G);
    fx(B, G, R);
    fx(B, R, G);
    fx(G, R, B);
    fx(G, B, R);
    cout << ans << endl;
  }
}
