#include <bits/stdc++.h>
using namespace std;
void input_array(vector<long long int> &A) {
  for (int i = 0; i < A.size(); i++) cin >> A[i];
}
long long int res;
void find_gems(vector<long long int> &a, vector<long long int> &b,
               vector<long long int> &c) {
  for (auto x : a) {
    auto it1 = lower_bound(b.begin(), b.end(), x);
    auto it2 = upper_bound(c.begin(), c.end(), x);
    if (it1 == b.end() || it2 == c.begin()) continue;
    it2--;
    long long int y = *it1, z = *it2;
    res = min(res, (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x));
  }
}
int main() {
  int o;
  cin >> o;
  while (o--) {
    int r, g, b;
    cin >> r >> g >> b;
    vector<long long int> red(r), green(g), blue(b);
    input_array(red);
    input_array(green);
    input_array(blue);
    sort(red.begin(), red.end());
    sort(green.begin(), green.end());
    sort(blue.begin(), blue.end());
    res = LLONG_MAX;
    find_gems(red, blue, green);
    find_gems(red, green, blue);
    find_gems(blue, red, green);
    find_gems(blue, green, red);
    find_gems(green, red, blue);
    find_gems(green, blue, red);
    cout << res << endl;
  }
  return 0;
}
