#include <bits/stdc++.h>
using namespace std;
int n[3];
int a[3][100000];
long long f(int x, int y, int z) {
  long long ans = 0;
  ans += ((long long)x - y) * ((long long)x - y);
  ans += ((long long)x - z) * ((long long)x - z);
  ans += ((long long)y - z) * ((long long)y - z);
  return ans;
}
int binSearch(int x, int i) {
  int beg = 0;
  int last = n[i] - 1;
  while (beg < last) {
    int mid = beg + (last - beg + 1) / 2;
    if (a[i][mid] <= x)
      beg = mid;
    else
      last = mid - 1;
  }
  if (a[i][beg] > x) return -1;
  return beg;
}
long long cal(int x, int y, int z) {
  long long ans = 9223372036854775807;
  for (int i = 0; i < int(n[y]); i++) {
    int b = binSearch(a[y][i], x);
    int c = binSearch(a[y][i], z);
    if (c == -1)
      c = 0;
    else if (a[z][c] != a[y][i])
      c++;
    if (b != -1 && c != n[z]) ans = min(ans, f(a[x][b], a[y][i], a[z][c]));
  }
  return ans;
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    for (int i = 0; i < int(3); i++) cin >> n[i];
    for (int i = 0; i < int(n[0]); i++) cin >> a[0][i];
    for (int i = 0; i < int(n[1]); i++) cin >> a[1][i];
    for (int i = 0; i < int(n[2]); i++) cin >> a[2][i];
    sort(a[0], a[0] + n[0]);
    sort(a[1], a[1] + n[1]);
    sort(a[2], a[2] + n[2]);
    long long ans = 9223372036854775807;
    ans = min(ans, cal(0, 1, 2));
    ans = min(ans, cal(2, 1, 0));
    ans = min(ans, cal(0, 2, 1));
    ans = min(ans, cal(1, 2, 0));
    ans = min(ans, cal(1, 0, 2));
    ans = min(ans, cal(2, 0, 1));
    cout << ans << "\n";
  }
  return 0;
}
