#include <bits/stdc++.h>
#pragma warning(disable : 4996)
const long long MOD = 1000000007;
using namespace std;
void solve() {
  int a[3];
  scanf("%d%d%d", &a[0], &a[1], &a[2]);
  int i;
  vector<vector<int> > v(3);
  int k;
  for (k = 0; k < 3; k++) {
    v[k].resize(a[k]);
    for (i = 0; i < a[k]; i++) {
      scanf("%d", &(v[k][i]));
    }
    sort(v[k].begin(), v[k].end());
  }
  long long ans = 9223300000000000000;
  for (k = 0; k < 3; k++) {
    int j = (k + 1) % 3;
    int j2 = (k + 2) % 3;
    for (i = 0; i < (int)v[k].size(); i++) {
      int curr = v[k][i];
      int tt = lower_bound(v[j].begin(), v[j].end(), curr + 1) - v[j].begin();
      if (tt == 0) continue;
      tt--;
      int tt2 = lower_bound(v[j2].begin(), v[j2].end(), curr) - v[j2].begin();
      if (tt2 < (int)v[j2].size()) {
        int curr0 = v[j][tt];
        int curr2 = v[j2][tt2];
        long long ans0 =
            ((long long)curr0 - curr) * ((long long)curr0 - curr) +
            ((long long)curr2 - curr) * ((long long)curr2 - curr) +
            ((long long)curr0 - curr2) * ((long long)curr0 - curr2);
        ans = ((ans) > (ans0) ? (ans0) : (ans));
      }
    }
    j2 = (k + 1) % 3;
    j = (k + 2) % 3;
    for (i = 0; i < (int)v[k].size(); i++) {
      int curr = v[k][i];
      int tt = lower_bound(v[j].begin(), v[j].end(), curr + 1) - v[j].begin();
      if (tt == 0) continue;
      tt--;
      int tt2 = lower_bound(v[j2].begin(), v[j2].end(), curr) - v[j2].begin();
      if (tt2 < (int)v[j2].size()) {
        int curr0 = v[j][tt];
        int curr2 = v[j2][tt2];
        long long ans0 =
            ((long long)curr0 - curr) * ((long long)curr0 - curr) +
            ((long long)curr2 - curr) * ((long long)curr2 - curr) +
            ((long long)curr0 - curr2) * ((long long)curr0 - curr2);
        ans = ((ans) > (ans0) ? (ans0) : (ans));
      }
    }
  }
  printf("%lld\n", ans);
  return;
}
int main(int argc, char* argv[]) {
  int T;
  scanf("%d", &T);
  int t;
  for (t = 0; t < T; t++) {
    solve();
  }
  return 0;
}
