#include <bits/stdc++.h>
using namespace std;
long double ans = LLONG_MAX;
long double power(long double x) { return x * x; }
void solve(vector<int> vt1, vector<int> vt2, vector<int> vt3) {
  for (int i = 0; i < vt1.size(); ++i) {
    int ll = lower_bound(vt2.begin(), vt2.end(), vt1[i]) - vt2.begin();
    int up = upper_bound(vt3.begin(), vt3.end(), vt1[i]) - vt3.begin();
    int up1 = lower_bound(vt3.begin(), vt3.end(), vt1[i]) - vt3.begin();
    if (up > vt3.size() || (ll > vt2.size()) || (ll < 0)) continue;
    if (up == vt3.size()) --up;
    if (ll == vt2.size())
      --ll;
    else if (vt2[ll] != vt1[i]) {
      if (ll != 0) --ll;
    }
    if ((vt3[up1] == vt1[i]) && (up1 < vt3.size())) up = up1;
    long double temp = power((vt2[ll] - vt3[up])) + power((vt1[i] - vt2[ll])) +
                       power((vt3[up] - vt1[i]));
    if (temp < ans) ans = temp;
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    ans = LLONG_MAX;
    int r, g, b;
    cin >> r >> g >> b;
    vector<int> red(r, 0);
    vector<int> green(g, 0);
    vector<int> blue(b, 0);
    for (int i = 0; i < r; ++i) cin >> red[i];
    for (int i = 0; i < g; ++i) cin >> green[i];
    for (int i = 0; i < b; ++i) cin >> blue[i];
    sort(red.begin(), red.end());
    sort(green.begin(), green.end());
    sort(blue.begin(), blue.end());
    solve(red, green, blue);
    solve(red, blue, green);
    solve(blue, red, green);
    solve(blue, green, red);
    solve(green, red, blue);
    solve(green, blue, red);
    cout << fixed << setprecision(0) << ans << endl;
  }
  return 0;
}
