#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const unsigned long long INF = 3e18;
unsigned long long F(long long x, long long y) {
  return 1ll * (x - y) * (x - y);
}
bool valid(int x, int y) { return x >= 0 && x < y; }
unsigned long long solve(vector<int> &r, vector<int> &g, vector<int> &b) {
  unsigned long long ans = INF;
  for (auto x : r) {
    int G = lower_bound(g.begin(), g.end(), x) - g.begin();
    if (!valid(G, (int)g.size())) continue;
    int y = (x + g[G]) / 2;
    int B = upper_bound(b.begin(), b.end(), y) - b.begin();
    if (valid(G, (int)g.size()) && valid(B, (int)b.size()))
      ans = min(ans, F(x, g[G]) + F(x, b[B]) + F(g[G], b[B]));
    B--;
    if (valid(G, (int)g.size()) && valid(B, (int)b.size()))
      ans = min(ans, F(x, g[G]) + F(x, b[B]) + F(g[G], b[B]));
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int nr, ng, nb;
    cin >> nr >> ng >> nb;
    vector<int> r(nr), g(ng), b(nb);
    for (auto &x : r) cin >> x;
    for (auto &x : g) cin >> x;
    for (auto &x : b) cin >> x;
    sort(r.begin(), r.end());
    sort(g.begin(), g.end());
    sort(b.begin(), b.end());
    unsigned long long ans = solve(r, g, b);
    ans = min(ans, solve(r, b, g));
    ans = min(ans, solve(g, r, b));
    ans = min(ans, solve(g, b, r));
    ans = min(ans, solve(b, r, g));
    ans = min(ans, solve(b, g, r));
    cout << ans << '\n';
  }
  return 0;
}
