#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long mod0 = 1e9 + 7;
const long long mod1 = 998244353;
const long long mod2 = 1e9 + 9;
const long long mod3 = 2147483647;
const long long inf0 = 2e9;
const int inf = 1e9;
const long long INF = 2e18;
const long double eps = 1e-15;
void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void solve() {
  vector<int> n(3);
  for (int i = 0; i < 3; ++i) cin >> n[i];
  vector<vector<int> > a(3);
  for (int i = 0; i < 3; ++i) {
    a[i].resize(n[i]);
    for (int j = 0; j < n[i]; ++j) cin >> a[i][j];
  }
  for (int i = 0; i < 3; ++i) sort((a[i]).begin(), (a[i]).end());
  vector<vector<int> > P = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2},
                            {1, 2, 0}, {2, 0, 1}, {2, 1, 0}};
  long long ans = INF;
  for (vector<int> p : P) {
    for (int i = 0; i < n[p[1]]; ++i) {
      long long y = a[p[1]][i];
      if (a[p[0]][0] > y || a[p[2]].back() < y) continue;
      long long x = *(--upper_bound((a[p[0]]).begin(), (a[p[0]]).end(), y));
      long long z = *lower_bound((a[p[2]]).begin(), (a[p[2]]).end(), y);
      ans = min(ans, (x - y) * (x - y) + (x - z) * (x - z) + (y - z) * (y - z));
    }
  }
  cout << ans << '\n';
}
bool multitest = true;
int main() {
  init();
  int t = 1;
  if (multitest) cin >> t;
  for (int i = 0; i < t; ++i) solve();
}
