#include <bits/stdc++.h>
using namespace std;
int t, nr, ng, nb;
long long ret;
long long sq(int a) { return 1LL * a * 1LL * a; }
void go(vector<int> x_list, vector<int> y_list, vector<int> z_list) {
  for (int y : y_list) {
    auto x = upper_bound(x_list.begin(), x_list.end(), y);
    auto z = lower_bound(z_list.begin(), z_list.end(), y);
    if (x == x_list.begin() || z == z_list.end()) continue;
    x--;
    ret = min(ret, sq(*x - y) + sq(y - *z) + sq(*z - *x));
  }
}
int main() {
  cin >> t;
  while (t--) {
    cin >> nr >> ng >> nb;
    vector<int> r(nr);
    vector<int> g(ng);
    vector<int> b(nb);
    for (int &i : r) cin >> i;
    for (int &i : g) cin >> i;
    for (int &i : b) cin >> i;
    sort(r.begin(), r.end());
    sort(g.begin(), g.end());
    sort(b.begin(), b.end());
    ret = sq(r[0] - g[0]) + sq(g[0] - b[0]) + sq(b[0] - r[0]);
    go(r, g, b);
    go(r, b, g);
    go(g, b, r);
    go(g, r, b);
    go(b, g, r);
    go(b, r, g);
    cout << ret << "\n";
  }
  return 0;
}
