#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
const long long int inf = 9e18;
void __print(long long int x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  long long int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
long long int giveVal(long long int x, long long int y, long long int z) {
  return (x - y) * (x - y) + (z - y) * (z - y) + (z - x) * (z - x);
}
long long int solve(vector<long long int> &a, vector<long long int> &b,
                    vector<long long int> &c) {
  long long int ans = inf;
  for (auto val : b) {
    auto lesser_it = upper_bound(a.begin(), a.end(), val);
    auto greater_it = lower_bound(c.begin(), c.end(), val);
    if (lesser_it == a.begin() || greater_it == c.end()) {
      continue;
    }
    lesser_it--;
    ans = min(ans, giveVal(*lesser_it, val, *greater_it));
  }
  return ans;
}
void tc() {
  long long int nr, ng, nb;
  cin >> nr >> ng >> nb;
  vector<long long int> r(nr), g(ng), b(nb);
  for (long long int i = 0; i < nr; i++) {
    cin >> r[i];
  }
  for (long long int i = 0; i < ng; i++) {
    cin >> g[i];
  }
  for (long long int i = 0; i < nb; i++) {
    cin >> b[i];
  }
  sort(r.begin(), r.end());
  sort(g.begin(), g.end());
  sort(b.begin(), b.end());
  long long int ans = inf;
  ans = min(ans, solve(r, g, b));
  ans = min(ans, solve(b, g, r));
  ans = min(ans, solve(g, r, b));
  ans = min(ans, solve(b, r, g));
  ans = min(ans, solve(r, b, g));
  ans = min(ans, solve(g, b, r));
  cout << ans << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--) {
    tc();
  }
}
