#include <bits/stdc++.h>
using namespace std;
long long solve(long long a, long long b, long long c) {
  long long a1 = a - c;
  a1 *= a1;
  long long b1 = c - b;
  b1 *= b1;
  long long c1 = b - a;
  c1 *= c1;
  return a1 + b1 + c1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  cin >> t;
  while (t--) {
    long long a, b, c;
    cin >> a >> b >> c;
    vector<long long> arr(a, 0), arr1(b, 0), arr2(c, 0);
    for (int i = 0; i < a; i++) {
      cin >> arr[i];
    }
    for (int i = 0; i < b; i++) {
      cin >> arr1[i];
    }
    for (int i = 0; i < c; i++) {
      cin >> arr2[i];
    }
    sort((arr).begin(), (arr).end());
    sort((arr1).begin(), (arr1).end());
    sort((arr2).begin(), (arr2).end());
    long long ans = 4 * (1e18);
    vector<long long>::iterator it;
    it = unique((arr).begin(), (arr).end());
    arr.resize(distance(arr.begin(), it));
    it = unique((arr1).begin(), (arr1).end());
    arr1.resize(distance(arr1.begin(), it));
    it = unique((arr2).begin(), (arr2).end());
    arr2.resize(distance(arr2.begin(), it));
    a = arr.size();
    b = arr1.size();
    c = arr2.size();
    for (int i = 0; i < a; i++) {
      long long in =
          lower_bound((arr1).begin(), (arr1).end(), arr[i]) - arr1.begin();
      vector<long long> a1;
      vector<long long> b1;
      if (in == b) {
        a1.push_back(arr1[in - 1]);
      } else {
        a1.push_back(arr1[in]);
        if (in < b - 1) {
          a1.push_back(arr1[in + 1]);
        }
        if (in > 0) {
          a1.push_back(arr1[in - 1]);
        }
      }
      in = lower_bound((arr2).begin(), (arr2).end(), arr[i]) - arr2.begin();
      if (in == c) {
        b1.push_back(arr2[in - 1]);
      } else {
        b1.push_back(arr2[in]);
        if (in < c - 1) {
          b1.push_back(arr2[in + 1]);
        }
        if (in > 0) {
          b1.push_back(arr2[in - 1]);
        }
      }
      for (int j = 0; j < a1.size(); j++) {
        for (int l = 0; l < b1.size(); l++) {
          long long k = solve(arr[i], a1[j], b1[l]);
          ans = min(k, ans);
        }
      }
    }
    for (int i = 0; i < b; i++) {
      long long in =
          lower_bound((arr).begin(), (arr).end(), arr1[i]) - arr.begin();
      vector<long long> a1;
      vector<long long> b1;
      if (in == a) {
        a1.push_back(arr[in - 1]);
      } else {
        a1.push_back(arr[in]);
        if (in < a - 1) {
          a1.push_back(arr[in + 1]);
        }
        if (in > 0) {
          a1.push_back(arr[in - 1]);
        }
      }
      in = lower_bound((arr2).begin(), (arr2).end(), arr1[i]) - arr2.begin();
      if (in == c) {
        b1.push_back(arr2[in - 1]);
      } else {
        b1.push_back(arr2[in]);
        if (in < c - 1) {
          b1.push_back(arr2[in + 1]);
        }
        if (in > 0) {
          b1.push_back(arr2[in - 1]);
        }
      }
      for (int j = 0; j < a1.size(); j++) {
        for (int l = 0; l < b1.size(); l++) {
          long long k = solve(arr1[i], a1[j], b1[l]);
          ans = min(k, ans);
        }
      }
    }
    for (int i = 0; i < c; i++) {
      long long in =
          lower_bound((arr1).begin(), (arr1).end(), arr2[i]) - arr1.begin();
      vector<long long> a1;
      vector<long long> b1;
      if (in == b) {
        a1.push_back(arr1[in - 1]);
      } else {
        a1.push_back(arr1[in]);
        if (in < b - 1) {
          a1.push_back(arr1[in + 1]);
        }
        if (in > 0) {
          a1.push_back(arr1[in - 1]);
        }
      }
      in = lower_bound((arr).begin(), (arr).end(), arr2[i]) - arr.begin();
      if (in == a) {
        b1.push_back(arr[in - 1]);
      } else {
        b1.push_back(arr[in]);
        if (in < a - 1) {
          b1.push_back(arr[in + 1]);
        }
        if (in > 0) {
          b1.push_back(arr[in - 1]);
        }
      }
      for (int j = 0; j < a1.size(); j++) {
        for (int l = 0; l < b1.size(); l++) {
          long long k = solve(arr2[i], a1[j], b1[l]);
          ans = min(k, ans);
        }
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
