#include <bits/stdc++.h>
const int maxn = 5e5 + 10;
using namespace std;
vector<long long> red, blue, green;
long long ans = 0;
void thisfun(vector<long long> a, vector<long long> b, vector<long long> c) {
  for (int i = 0; i < a.size(); i++) {
    long long k = a[i];
    vector<long long>::iterator m1, m2;
    m1 = lower_bound(b.begin(), b.end(), a[i]);
    m2 = upper_bound(c.begin(), c.end(), a[i]);
    if (a[i] > b[b.size() - 1] or a[i] < c[0]) continue;
    m2--;
    long long c = *m1, cc = *m2;
    long long an =
        pow(abs(k - c), 2) + pow(abs(c - cc), 2) + pow(abs(k - cc), 2);
    if (an < 0) continue;
    if (an < ans) ans = an;
  }
}
int main() {
  cin.tie(0);
  cout.tie(0);
  long long m;
  scanf("%lli", &m);
  for (int i = 0; i < m; i++) {
    red.clear();
    blue.clear();
    green.clear();
    ans = 9e18;
    long long n1, n2, n3, x;
    scanf("%lli%lli%lli", &n1, &n2, &n3);
    for (int v = 0; v < n1; v++) {
      scanf("%lli", &x);
      red.push_back(x);
    }
    for (int v = 0; v < n2; v++) {
      scanf("%lli", &x);
      blue.push_back(x);
    }
    for (int v = 0; v < n3; v++) {
      scanf("%lli", &x);
      green.push_back(x);
    }
    sort(red.begin(), red.end());
    sort(green.begin(), green.end());
    sort(blue.begin(), blue.end());
    thisfun(red, green, blue);
    thisfun(red, blue, green);
    thisfun(green, blue, red);
    thisfun(green, red, blue);
    thisfun(blue, red, green);
    thisfun(blue, green, red);
    cout << ans << "\n";
  }
}
