#include <bits/stdc++.h>
using namespace std;
void solution() {
  int a, s, c;
  cin >> a >> s >> c;
  vector<long long> re(a), g(s), b(c);
  for (int i = 0; i < a; i++) {
    cin >> re[i];
  }
  for (int i = 0; i < s; i++) {
    cin >> g[i];
  }
  for (int i = 0; i < c; i++) {
    cin >> b[i];
  }
  sort(re.begin(), re.end());
  sort(b.begin(), b.end());
  sort(g.begin(), g.end());
  long long ans = INT64_MAX;
  for (int i = 0; i < a; i++) {
    long long cur_val = re[i];
    int l = 0, r = g.size() - 1;
    while (r - l > 1) {
      int mid = (r + l) / 2;
      if (g[mid] > cur_val) {
        r = mid;
      } else {
        l = mid;
      }
    }
    int first = l;
    l = 0, r = b.size() - 1;
    while (r - l > 1) {
      int mid = (r + l) / 2;
      if (b[mid] > cur_val) {
        r = mid;
      } else {
        l = mid;
      }
    }
    int second = l;
    for (int f = -2; f <= 2; f++) {
      for (int j = -2; j <= 2; j++) {
        if (0 <= first + f && first + f <= g.size() - 1) {
          if (0 <= second + j && second + j <= b.size() - 1) {
            ans =
                min(ans, (re[i] - g[first + f]) * (re[i] - g[first + f]) +
                             (g[first + f] - b[second + j]) *
                                 (g[first + f] - b[second + j]) +
                             (b[second + j] - re[i]) * (b[second + j] - re[i]));
          }
        }
      }
    }
  }
  for (int i = 0; i < g.size(); i++) {
    long long cur_val = g[i];
    int l = 0, r = re.size() - 1;
    while (r - l > 1) {
      int mid = (r + l) / 2;
      if (re[mid] > cur_val) {
        r = mid;
      } else {
        l = mid;
      }
    }
    int first = l;
    l = 0, r = b.size() - 1;
    while (r - l > 1) {
      int mid = (r + l) / 2;
      if (b[mid] > cur_val) {
        r = mid;
      } else {
        l = mid;
      }
    }
    int second = l;
    for (int f = -2; f <= 2; f++) {
      for (int j = -2; j <= 2; j++) {
        if (0 <= first + f && first + f <= re.size() - 1) {
          if (0 <= second + j && second + j <= b.size() - 1) {
            ans = min(ans, (g[i] - re[first + f]) * (g[i] - re[first + f]) +
                               (re[first + f] - b[second + j]) *
                                   (re[first + f] - b[second + j]) +
                               (b[second + j] - g[i]) * (b[second + j] - g[i]));
          }
        }
      }
    }
  }
  for (int i = 0; i < b.size(); i++) {
    long long cur_val = b[i];
    int l = 0, r = g.size() - 1;
    while (r - l > 1) {
      int mid = (r + l) / 2;
      if (g[mid] > cur_val) {
        r = mid;
      } else {
        l = mid;
      }
    }
    int first = l;
    l = 0, r = re.size() - 1;
    while (r - l > 1) {
      int mid = (r + l) / 2;
      if (re[mid] > cur_val) {
        r = mid;
      } else {
        l = mid;
      }
    }
    int second = l;
    for (int f = -2; f <= 2; f++) {
      for (int j = -2; j <= 2; j++) {
        if (0 <= first + f && first + f <= g.size() - 1) {
          if (0 <= second + j && second + j <= re.size() - 1) {
            ans =
                min(ans, (b[i] - g[first + f]) * (b[i] - g[first + f]) +
                             (g[first + f] - re[second + j]) *
                                 (g[first + f] - re[second + j]) +
                             (re[second + j] - b[i]) * (re[second + j] - b[i]));
          }
        }
      }
    }
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    solution();
  }
}
