#include <bits/stdc++.h>
using namespace std;
long long C(long long a) { return a * a; }
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> v[3];
    for (int i = 0; i < a; i++) {
      long long p;
      cin >> p;
      v[0].push_back(p);
    }
    for (int i = 0; i < b; i++) {
      long long p;
      cin >> p;
      v[1].push_back(p);
    }
    for (int i = 0; i < c; i++) {
      long long p;
      cin >> p;
      v[2].push_back(p);
    }
    long long ans = 1ll << 62;
    for (int i = 0; i < 3; i++) sort(v[i].begin(), v[i].end());
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        for (int k = 0; k < 3; k++) {
          if (i == j || j == k || i == k) continue;
          for (auto it : v[i]) {
            auto p1 = lower_bound(v[j].begin(), v[j].end(), it);
            if (p1 == v[j].end()) continue;
            auto p2 = lower_bound(v[k].begin(), v[k].end(), (it + *p1 + 1) / 2);
            if (p2 != v[k].end())
              ans = min(ans, C(it - *p1) + C(*p1 - *p2) + C(*p2 - it));
            if (p2 != v[k].begin()) {
              p2--;
              ans = min(ans, C(it - *p1) + C(*p1 - *p2) + C(*p2 - it));
            }
          }
        }
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
