#include <bits/stdc++.h>
using namespace std;
int nr, ng, nb;
unsigned long long int ans = 9e18;
unsigned long long int square(int x) { return 1ll * x * x; }
void solve(std::vector<int> a, std::vector<int> b, std::vector<int> c) {
  std::vector<int>::iterator l, u;
  for (int i = 0; i < a.size(); i++) {
    l = lower_bound(b.begin(), b.end(), a[i]);
    u = upper_bound(c.begin(), c.end(), a[i]);
    if (u != c.begin() && l != b.end())
      u--, ans = min(ans,
                     square(*l - *u) + square(*u - a[i]) + square(*l - a[i]));
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> nr >> ng >> nb;
    std::vector<int> r, g, b;
    int x;
    for (int i = 0; i < nr; i++) cin >> x, r.push_back(x);
    for (int i = 0; i < ng; i++) cin >> x, g.push_back(x);
    for (int i = 0; i < nb; i++) cin >> x, b.push_back(x);
    sort(r.begin(), r.end());
    sort(g.begin(), g.end());
    sort(b.begin(), b.end());
    solve(r, g, b);
    solve(r, b, g);
    solve(b, r, g);
    solve(g, r, b);
    solve(b, g, r);
    solve(g, b, r);
    cout << ans << endl;
    ans = 9e18;
  }
}
