#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
int t, n[3], a[3][MAXN];
long long ans;
int main() {
  for (scanf("%d", &t); t--;) {
    for (int i = 0; i < 3; ++i) scanf("%d", &n[i]);
    ans = 0x3f3f3f3f3f3f3f3f;
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < n[i]; ++j) scanf("%d", &a[i][j]);
      sort(a[i], a[i] + n[i]);
    }
    for (int i = 0; i < 3; ++i)
      for (int j = 0; j < n[i]; ++j) {
        int x = a[i][j];
        pair<int, int> y_(-1, -1), z_(-1, -1);
        for (int k = 0; k < 3; ++k)
          if (k != i) {
            int w = *lower_bound(a[k], a[k] + n[k] - 1, x);
            if (y_.first == -1)
              y_ = make_pair(w, k);
            else
              z_ = make_pair(w, k);
          }
        if (y_ > z_) swap(y_, z_);
        int z = z_.first, vec = y_.second;
        int avg = (x + z) / 2;
        int *w = lower_bound(a[vec], a[vec] + n[vec] - 1, avg);
        int y = *w;
        ans = min(ans, 1LL * (x - y) * (x - y) + 1LL * (y - z) * (y - z) +
                           1LL * (x - z) * (x - z));
        if (w != a[vec]) {
          y = *(w - 1);
          ans = min(ans, 1LL * (x - y) * (x - y) + 1LL * (y - z) * (y - z) +
                             1LL * (x - z) * (x - z));
        }
      }
    printf("%lld\n", ans);
  }
}
