#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n1, n2, n3;
    cin >> n1 >> n2 >> n3;
    vector<int> v1;
    for (int i = 0; i < n1; i++) {
      int x;
      cin >> x;
      v1.push_back(x);
    }
    sort(v1.begin(), v1.end());
    vector<int> v2;
    for (int i = 0; i < n2; i++) {
      int x;
      cin >> x;
      v2.push_back(x);
    }
    sort(v2.begin(), v2.end());
    vector<int> v3;
    for (int i = 0; i < n3; i++) {
      int x;
      cin >> x;
      v3.push_back(x);
    }
    sort(v3.begin(), v3.end());
    long long ans = 8e18;
    for (int i = 0; i < n1; i++) {
      auto idx = lower_bound(v2.begin(), v2.end(), v1[i]) - v2.begin();
      for (int d = -1; d <= 1; d++) {
        if (0 <= idx + d && idx + d < n2) {
          auto jdx = lower_bound(v3.begin(), v3.end(), v1[i]) - v3.begin();
          for (int e = -1; e <= 1; e++) {
            if (0 <= jdx + e && jdx + e < n3) {
              ans = min(
                  ans, 1ll * (v1[i] - v2[idx + d]) * (v1[i] - v2[idx + d]) +
                           1ll * (v2[idx + d] - v3[jdx + e]) *
                               (v2[idx + d] - v3[jdx + e]) +
                           1ll * (v3[jdx + e] - v1[i]) * (v3[jdx + e] - v1[i]));
            }
          }
        }
      }
    }
    for (int i = 0; i < n2; i++) {
      auto idx = lower_bound(v3.begin(), v3.end(), v2[i]) - v3.begin();
      for (int d = -1; d <= 1; d++) {
        if (0 <= idx + d && idx + d < n3) {
          auto jdx = lower_bound(v1.begin(), v1.end(), v2[i]) - v1.begin();
          for (int e = -1; e <= 1; e++) {
            if (0 <= jdx + e && jdx + e < n1) {
              ans = min(
                  ans, 1ll * (v2[i] - v3[idx + d]) * (v2[i] - v3[idx + d]) +
                           1ll * (v3[idx + d] - v1[jdx + e]) *
                               (v3[idx + d] - v1[jdx + e]) +
                           1ll * (v1[jdx + e] - v2[i]) * (v1[jdx + e] - v2[i]));
            }
          }
        }
      }
    }
    for (int i = 0; i < n3; i++) {
      auto idx = lower_bound(v1.begin(), v1.end(), v3[i]) - v1.begin();
      for (int d = -1; d <= 1; d++) {
        if (0 <= idx + d && idx + d < n1) {
          auto jdx = lower_bound(v2.begin(), v2.end(), v3[i]) - v2.begin();
          for (int e = -1; e <= 1; e++) {
            if (0 <= jdx + e && jdx + e < n2) {
              ans = min(
                  ans, 1ll * (v3[i] - v1[idx + d]) * (v3[i] - v1[idx + d]) +
                           1ll * (v1[idx + d] - v2[jdx + e]) *
                               (v1[idx + d] - v2[jdx + e]) +
                           1ll * (v2[jdx + e] - v3[i]) * (v2[jdx + e] - v3[i]));
            }
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
