#include <bits/stdc++.h>
using namespace std;
double eps = 1e-9;
pair<int, int> get_closer(int a, vector<int> &v) {
  auto it = lower_bound(v.begin(), v.end(), a);
  int b = 2000000000, c = 2000000000;
  if (it != v.end()) b = *it;
  if (it != v.begin()) c = *(it - 1);
  return {c, b};
}
unsigned long long int count(int a, int b, int c) {
  return (a - b) * 1LL * (a - b) + (a - c) * 1LL * (a - c) +
         (b - c) * 1LL * (b - c);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n1, n2, n3;
    scanf("%d %d %d", &n1, &n2, &n3);
    vector<int> r(n1), g(n2), b(n3);
    for (int i = 0; i < n1; i++) scanf("%d", &r[i]);
    for (int i = 0; i < n2; i++) scanf("%d", &g[i]);
    for (int i = 0; i < n3; i++) scanf("%d", &b[i]);
    sort(r.begin(), r.end());
    sort(g.begin(), g.end());
    sort(b.begin(), b.end());
    unsigned long long int mn = count(r[0], b[0], g[0]);
    for (int i = 0; i < n1; i++) {
      int a = r[i];
      pair<int, int> p1 = get_closer(a, g);
      pair<int, int> p2 = get_closer(a, b);
      pair<int, int> p3 = get_closer(p1.first, b);
      pair<int, int> p4 = get_closer(p1.second, b);
      mn = min(mn, count(a, p1.first, p2.first));
      mn = min(mn, count(a, p1.second, p2.first));
      mn = min(mn, count(a, p1.first, p2.second));
      mn = min(mn, count(a, p1.second, p2.second));
      mn = min(mn, count(a, p1.first, p3.first));
      mn = min(mn, count(a, p1.first, p3.second));
      mn = min(mn, count(a, p1.second, p4.first));
      mn = min(mn, count(a, p1.second, p4.second));
    }
    for (int i = 0; i < n2; i++) {
      int a = g[i];
      pair<int, int> p1 = get_closer(a, r);
      pair<int, int> p2 = get_closer(a, b);
      pair<int, int> p3 = get_closer(p1.first, b);
      pair<int, int> p4 = get_closer(p1.second, b);
      mn = min(mn, count(a, p1.first, p2.first));
      mn = min(mn, count(a, p1.second, p2.first));
      mn = min(mn, count(a, p1.first, p2.second));
      mn = min(mn, count(a, p1.second, p2.second));
      mn = min(mn, count(a, p1.first, p3.first));
      mn = min(mn, count(a, p1.first, p3.second));
      mn = min(mn, count(a, p1.second, p4.first));
      mn = min(mn, count(a, p1.second, p4.second));
    }
    for (int i = 0; i < n3; i++) {
      int a = b[i];
      pair<int, int> p1 = get_closer(a, g);
      pair<int, int> p2 = get_closer(a, r);
      pair<int, int> p3 = get_closer(p1.first, r);
      pair<int, int> p4 = get_closer(p1.second, r);
      mn = min(mn, count(a, p1.first, p2.first));
      mn = min(mn, count(a, p1.second, p2.first));
      mn = min(mn, count(a, p1.first, p2.second));
      mn = min(mn, count(a, p1.second, p2.second));
      mn = min(mn, count(a, p1.first, p3.first));
      mn = min(mn, count(a, p1.first, p3.second));
      mn = min(mn, count(a, p1.second, p4.first));
      mn = min(mn, count(a, p1.second, p4.second));
    }
    cout << mn << '\n';
  }
  return 0;
}
