#include <bits/stdc++.h>
using namespace std;
long long raise(long long bs, long long pw) {
  if (pw == 0) return 1;
  if (pw == 1) return bs;
  long long ret = raise(bs, pw / 2);
  ret = (ret * ret);
  if (pw % 2) ret = (ret * bs);
  return (ret);
}
long long pw(long long a, long long b, long long c) {
  return raise(a - b, 2) + raise(a - c, 2) + raise(b - c, 2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int a, b, c;
    cin >> a >> b >> c;
    vector<long long> aa(a), bb(b), cc(c);
    for (int i = 0; i < a; i++) cin >> aa[i];
    for (int i = 0; i < b; i++) cin >> bb[i];
    for (int i = 0; i < c; i++) cin >> cc[i];
    sort(aa.begin(), aa.end());
    sort(bb.begin(), bb.end());
    sort(cc.begin(), cc.end());
    long long mn = LLONG_MAX;
    for (int i = 0; i < a; i++) {
      vector<long long> bp, cp;
      auto bi = upper_bound(bb.begin(), bb.end(), aa[i]);
      auto ci = upper_bound(cc.begin(), cc.end(), aa[i]);
      if (bi != bb.end()) bp.push_back(*bi);
      if (bi != bb.begin()) bp.push_back(*(--bi));
      if (ci != cc.end()) cp.push_back(*ci);
      if (ci != cc.begin()) cp.push_back(*(--ci));
      for (auto &e : bp) {
        auto cr = upper_bound(cc.begin(), cc.end(), (aa[i] + e) / 2.0);
        if (cr != cc.end())
          if (1)
            mn = min(mn, pw(aa[i], e, *cr));
          else
            mn = max(mn, pw(aa[i], e, *cr));
        if (cr != cc.begin())
          if (1)
            mn = min(mn, pw(aa[i], e, *(--cr)));
          else
            mn = max(mn, pw(aa[i], e, *(--cr)));
      }
      for (auto &e : cp) {
        auto br = upper_bound(bb.begin(), bb.end(), (aa[i] + e) / 2.0);
        if (br != bb.end())
          if (1)
            mn = min(mn, pw(aa[i], e, *br));
          else
            mn = max(mn, pw(aa[i], e, *br));
        if (br != bb.begin())
          if (1)
            mn = min(mn, pw(aa[i], e, *(--br)));
          else
            mn = max(mn, pw(aa[i], e, *(--br)));
      }
    }
    cout << (long long)mn << endl;
  }
}
