#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7, INF = 8e18;
const int N = 1e5 + 5;
long long int ans;
long long int sq(long long int val) { return val * val; }
void solve(vector<int> a, vector<int> b, vector<int> c) {
  for (auto it : a) {
    auto x = lower_bound(b.begin(), b.end(), it);
    auto y = upper_bound(c.begin(), c.end(), it);
    if (x == b.end() || y == c.begin()) {
      continue;
    }
    y--;
    ans = min(ans, sq(it - *x) + sq(*x - *y) + sq(*y - it));
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int r, g, bl;
    cin >> r >> g >> bl;
    vector<int> a(r), b(g), c(bl);
    for (int i = 0; i < r; i++) cin >> a[i];
    for (int i = 0; i < g; i++) cin >> b[i];
    for (int i = 0; i < bl; i++) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    ans = INF;
    solve(a, b, c);
    solve(a, c, b);
    solve(b, a, c);
    solve(b, c, a);
    solve(c, a, b);
    solve(c, b, a);
    cout << ans << "\n";
  }
  return 0;
}
