#include <bits/stdc++.h>
using namespace std;
void File() {}
void fast() {
  ios::sync_with_stdio(NULL);
  cout.tie(NULL);
  cin.tie(NULL);
  File();
}
const double pi = 2 * acos(0.0);
const long long oo = 2e18;
const int MOD = 1e9 + 7;
const int nn = 2e5 + 15;
int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};
vector<pair<int, int> > vec;
long long solve(int idx, vector<long long> vv, map<int, int> vis) {
  if (idx >= ((int)((vec).size()))) {
    if (((int)((vv).size())) == 3) {
      vector<long long> tmp(((vv).begin()), ((vv).end()));
      sort(((tmp).begin()), ((tmp).end()));
      return (tmp[0] - tmp[1]) * (tmp[0] - tmp[1]) +
             (tmp[0] - tmp[2]) * (tmp[0] - tmp[2]) +
             (tmp[2] - tmp[1]) * (tmp[2] - tmp[1]);
    }
    return oo;
  }
  long long c1 = solve(idx + 1, vv, vis), cnt2 = oo;
  if (!vis[vec[idx].second]) {
    vv.push_back(vec[idx].first);
    vis[vec[idx].second]++;
    cnt2 = solve(idx + 1, vv, vis);
  }
  return min(c1, cnt2);
}
int main() {
  fast();
  int tc;
  cin >> tc;
  while (tc--) {
    int r, g, b;
    cin >> r >> g >> b;
    vector<int> red(r);
    vector<int> greenPos(g);
    vector<int> bluePos(b);
    for (int i = 0; i < r; i++) cin >> red[i];
    for (int i = 0; i < g; i++) cin >> greenPos[i];
    for (int i = 0; i < b; i++) cin >> bluePos[i];
    sort(((red).begin()), ((red).end()));
    sort(((greenPos).begin()), ((greenPos).end()));
    sort(((bluePos).begin()), ((bluePos).end()));
    long long mn = oo;
    for (int i = 0; i < r; i++) {
      vec.push_back({red[i], 0});
      int it = lower_bound(((greenPos).begin()), ((greenPos).end()), red[i]) -
               greenPos.begin();
      if (it == g) it--;
      vec.push_back({greenPos[it], 1});
      vec.push_back({greenPos[max(0, it - 1)], 1});
      it = lower_bound(((bluePos).begin()), ((bluePos).end()), red[i]) -
           bluePos.begin();
      if (it == b) it--;
      vec.push_back({bluePos[it], 2});
      vec.push_back({bluePos[max(0, it - 1)], 2});
      vector<long long> vv;
      map<int, int> mp;
      mn = min(mn, solve(0, vv, mp));
      vec.clear();
    }
    for (int i = 0; i < g; i++) {
      int x = greenPos[i];
      vec.push_back({x, 0});
      int it = lower_bound(((red).begin()), ((red).end()), x) - red.begin();
      if (it == r) it--;
      vec.push_back({red[it], 1});
      vec.push_back({red[max(0, it - 1)], 1});
      it = lower_bound(((bluePos).begin()), ((bluePos).end()), x) -
           bluePos.begin();
      if (it == b) it--;
      vec.push_back({bluePos[it], 2});
      vec.push_back({bluePos[max(it - 1, 0)], 2});
      vector<long long> vv;
      map<int, int> mp;
      mn = min(mn, solve(0, vv, mp));
      vec.clear();
    }
    for (int i = 0; i < b; i++) {
      int x = bluePos[i];
      vec.push_back({x, 0});
      int it = lower_bound(((red).begin()), ((red).end()), x) - red.begin();
      if (it == r) it--;
      vec.push_back({red[it], 1});
      vec.push_back({red[max(0, it - 1)], 1});
      it = lower_bound(((greenPos).begin()), ((greenPos).end()), x) -
           greenPos.begin();
      if (it == g) it--;
      vec.push_back({greenPos[it], 2});
      vec.push_back({greenPos[max(0, it - 1)], 2});
      vector<long long> vv;
      map<int, int> mp;
      mn = min(mn, solve(0, vv, mp));
      vec.clear();
    }
    cout << mn << "\n";
  }
  return 0;
}
