#include <bits/stdc++.h>
using namespace std;
long long int minimum(vector<long int> x, vector<long int> y,
                      vector<long int> z) {
  long long int value = std::numeric_limits<long long int>::max();
  for (int i = 0; i < y.size(); i++) {
    long long int sum = 0;
    int flag = -1;
    vector<long int>::iterator low;
    low = lower_bound(x.begin(), x.end(), y[i]);
    int temp = low - x.begin();
    if ((x[temp] > y[i]) || (temp == x.size())) temp--;
    if (temp >= 0) {
      long long int num = y[i] - x[temp];
      sum += num * num;
    } else
      flag = 1;
    low = lower_bound(z.begin(), z.end(), y[i]);
    int temp2 = low - z.begin();
    if (temp2 != z.size()) {
      long long int num = z[temp2] - y[i];
      sum += num * num;
    } else
      flag = 1;
    if (flag == -1) {
      long long int num = z[temp2] - x[temp];
      sum += num * num;
    }
    if ((sum < value) && (flag == -1)) value = sum;
  }
  return value;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int r, g, x;
    cin >> r >> g >> x;
    vector<long int> a, b, c;
    long int num;
    for (int i = 0; i < r; i++) {
      cin >> num;
      a.push_back(num);
    }
    for (int i = 0; i < g; i++) {
      cin >> num;
      b.push_back(num);
    }
    for (int i = 0; i < x; i++) {
      cin >> num;
      c.push_back(num);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    long long int ans = std::numeric_limits<long long int>::max();
    long long int temp = minimum(a, b, c);
    if (temp < ans) ans = temp;
    temp = minimum(a, c, b);
    if (temp < ans) ans = temp;
    temp = minimum(b, a, c);
    if (temp < ans) ans = temp;
    temp = minimum(b, c, a);
    if (temp < ans) ans = temp;
    temp = minimum(c, a, b);
    if (temp < ans) ans = temp;
    temp = minimum(c, b, a);
    if (temp < ans) ans = temp;
    cout << ans << "\n";
  }
}
