#include <bits/stdc++.h>
using namespace std;
long long get(long long x, long long y, long long z) {
  return (x - y) * (x - y) + (x - z) * (x - z) + (y - z) * (y - z);
}
long long get(vector<long long> &a, vector<long long> &b,
              vector<long long> &c) {
  long long ans = 9e18;
  for (auto x : a) {
    int id = lower_bound(b.begin(), b.end(), x) - b.begin();
    if (id == int(b.size())) break;
    int id2 = lower_bound(c.begin(), c.end(), b[id]) - c.begin();
    if (id2 == int(c.size())) break;
    long long z = c[id2];
    int it = lower_bound(b.begin(), b.end(), (x + z) / 2) - b.begin();
    for (int i = -20, ThxDem = 20; i < ThxDem; ++i)
      if (it + i >= 0 && it + i < int(b.size())) {
        long long y = b[it + i];
        ans = min(ans, get(x, y, z));
      }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m, k;
    cin >> n >> m >> k;
    vector<long long> a(n), b(m), c(k);
    for (int i = 0, ThxDem = n; i < ThxDem; ++i) cin >> a[i];
    for (int i = 0, ThxDem = m; i < ThxDem; ++i) cin >> b[i];
    for (int i = 0, ThxDem = k; i < ThxDem; ++i) cin >> c[i];
    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());
    sort(b.begin(), b.end());
    b.erase(unique(b.begin(), b.end()), b.end());
    sort(c.begin(), c.end());
    c.erase(unique(c.begin(), c.end()), c.end());
    long long ans = 9e18;
    ans = min(ans, get(a, b, c));
    ans = min(ans, get(a, c, b));
    ans = min(ans, get(b, a, c));
    ans = min(ans, get(b, c, a));
    ans = min(ans, get(c, a, b));
    ans = min(ans, get(c, b, a));
    cout << ans << "\n";
  }
}
