#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 5;
const long long INF = 4e18;
int n, m, k;
int a[MAX_N], b[MAX_N], c[MAX_N];
long long sqr(int x) { return 1ll * x * x; }
long long get(int i, int j, int f) {
  long long res = 0;
  res += sqr(a[i] - b[j]);
  res += sqr(a[i] - c[f]);
  res += sqr(b[j] - c[f]);
  return res;
}
void solve() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= m; ++i) {
    cin >> b[i];
  }
  for (int i = 1; i <= k; ++i) {
    cin >> c[i];
  }
  sort(a + 1, a + n + 1);
  sort(b + 1, b + m + 1);
  sort(c + 1, c + k + 1);
  long long ans = INF;
  for (int i = 1; i <= n; ++i) {
    int B = lower_bound(b + 1, b + m + 1, a[i]) - b;
    int C = lower_bound(c + 1, c + k + 1, a[i]) - c;
    for (int j = max(1, B - 2); j <= min(m, B + 2); ++j) {
      for (int f = max(1, C - 2); f <= min(k, C + 2); ++f) {
        ans = min(ans, get(i, j, f));
      }
    }
  }
  for (int j = 1; j <= m; ++j) {
    int A = lower_bound(a + 1, a + n + 1, b[j]) - a;
    int C = lower_bound(c + 1, c + k + 1, b[j]) - c;
    for (int i = max(1, A - 2); i <= min(n, A + 2); ++i) {
      for (int f = max(1, C - 2); f <= min(k, C + 2); ++f) {
        ans = min(ans, get(i, j, f));
      }
    }
  }
  for (int f = 1; f <= k; ++f) {
    int A = lower_bound(a + 1, a + n + 1, c[f]) - a;
    int B = lower_bound(b + 1, b + m + 1, c[f]) - b;
    for (int i = max(1, A - 2); i <= min(n, A + 2); ++i) {
      for (int j = max(1, B - 2); j <= min(m, B + 2); ++j) {
        ans = min(ans, get(i, j, f));
      }
    }
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int tests;
  cin >> tests;
  while (tests--) {
    solve();
  }
  return 0;
}
