#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T& a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T& a, T b) {
  return a < b ? (a = b, true) : false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  for (int qq = 1; qq <= tt; ++qq) {
    vector<vector<int>> gems(3);
    for (int i = 0; i < 3; ++i) {
      int n;
      cin >> n;
      gems[i].resize(n);
    }
    for (int i = 0; i < 3; ++i) {
      for (auto& v : gems[i]) cin >> v;
      sort(gems[i].begin(), gems[i].end());
    }
    auto val = [](long long a, long long b, long long c) {
      return (a - b) * (a - b) + (b - c) * (b - c) + (c - a) * (c - a);
    };
    long long ans = 5e18L;
    for (int x = 0; x < 3; ++x) {
      int y = (x + 1) % 3, z = (x + 2) % 3;
      int iy = 0, iz = 0;
      for (int ix = 0; ix < (int)gems[x].size(); ++ix) {
        while ((iy < int(gems[y].size())) && gems[y][iy] < gems[x][ix]) ++iy;
        while ((iz < int(gems[z].size())) && gems[z][iz] < gems[x][ix]) ++iz;
        for (int cy : {iy - 1, iy}) {
          if (0 <= cy && cy < (int)gems[y].size()) {
            for (int cz : {iz - 1, iz}) {
              if (0 <= cz && cz < (int)gems[z].size()) {
                uin(ans, val(gems[x][ix], gems[y][cy], gems[z][cz]));
              }
            }
          }
        }
      }
    }
    cout << ans << '\n';
  }
}
