#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int q;
  cin >> q;
  while (q--) {
    long long nr, ng, nb, val;
    cin >> nr >> ng >> nb;
    vector<long long> v[3];
    for (int i = 0; i < nr; i++) {
      cin >> val;
      v[0].push_back(val);
    }
    for (int i = 0; i < ng; i++) {
      cin >> val;
      v[1].push_back(val);
    }
    for (int i = 0; i < nb; i++) {
      cin >> val;
      v[2].push_back(val);
    }
    for (int i = 0; i < 3; i++) sort(v[i].begin(), v[i].end());
    long long ans = 3e18;
    for (int i = 0; i < v[0].size(); i++) {
      auto green2 = lower_bound(v[1].begin(), v[1].end(), v[0][i]);
      auto green1 = green2;
      green1--;
      if (green2 == v[1].end())
        green2 = green1;
      else if (green2 == v[1].begin())
        green1 = green2;
      auto blue22 = lower_bound(v[2].begin(), v[2].end(), *green2);
      auto blue21 = blue22;
      blue21--;
      if (blue22 == v[2].end())
        blue22 = blue21;
      else if (blue22 == v[2].begin())
        blue21 = blue22;
      auto blue12 = lower_bound(v[2].begin(), v[2].end(), *green1);
      auto blue11 = blue12;
      blue11--;
      if (blue12 == v[2].end())
        blue12 = blue11;
      else if (blue12 == v[2].begin())
        blue11 = blue12;
      vector<long long> choice;
      choice.push_back(((v[0][i] - (*green2)) * (v[0][i] - (*green2))) +
                       ((v[0][i] - (*blue22)) * (v[0][i] - (*blue22))) +
                       (((*green2) - (*blue22)) * ((*green2) - (*blue22))));
      choice.push_back(((v[0][i] - (*green2)) * (v[0][i] - (*green2))) +
                       ((v[0][i] - (*blue21)) * (v[0][i] - (*blue21))) +
                       (((*green2) - (*blue21)) * ((*green2) - (*blue21))));
      choice.push_back(((v[0][i] - (*green1)) * (v[0][i] - (*green1))) +
                       ((v[0][i] - (*blue12)) * (v[0][i] - (*blue12))) +
                       (((*green1) - (*blue12)) * ((*green1) - (*blue12))));
      choice.push_back(((v[0][i] - (*green1)) * (v[0][i] - (*green1))) +
                       ((v[0][i] - (*blue11)) * (v[0][i] - (*blue11))) +
                       (((*green1) - (*blue11)) * ((*green1) - (*blue11))));
      sort(choice.begin(), choice.end());
      ans = min(ans, choice[0]);
    }
    for (int i = 0; i < v[1].size(); i++) {
      auto green2 = lower_bound(v[0].begin(), v[0].end(), v[1][i]);
      auto green1 = green2;
      green1--;
      if (green2 == v[0].end())
        green2 = green1;
      else if (green2 == v[0].begin())
        green1 = green2;
      auto blue22 = lower_bound(v[2].begin(), v[2].end(), *green2);
      auto blue21 = blue22;
      blue21--;
      if (blue22 == v[2].end())
        blue22 = blue21;
      else if (blue22 == v[2].begin())
        blue21 = blue22;
      auto blue12 = lower_bound(v[2].begin(), v[2].end(), *green1);
      auto blue11 = blue12;
      blue11--;
      if (blue12 == v[2].end())
        blue12 = blue11;
      else if (blue12 == v[2].begin())
        blue11 = blue12;
      vector<long long> choice;
      choice.push_back(((v[1][i] - (*green2)) * (v[1][i] - (*green2))) +
                       ((v[1][i] - (*blue22)) * (v[1][i] - (*blue22))) +
                       (((*green2) - (*blue22)) * ((*green2) - (*blue22))));
      choice.push_back(((v[1][i] - (*green2)) * (v[1][i] - (*green2))) +
                       ((v[1][i] - (*blue21)) * (v[1][i] - (*blue21))) +
                       (((*green2) - (*blue21)) * ((*green2) - (*blue21))));
      choice.push_back(((v[1][i] - (*green1)) * (v[1][i] - (*green1))) +
                       ((v[1][i] - (*blue12)) * (v[1][i] - (*blue12))) +
                       (((*green1) - (*blue12)) * ((*green1) - (*blue12))));
      choice.push_back(((v[1][i] - (*green1)) * (v[1][i] - (*green1))) +
                       ((v[1][i] - (*blue11)) * (v[1][i] - (*blue11))) +
                       (((*green1) - (*blue11)) * ((*green1) - (*blue11))));
      sort(choice.begin(), choice.end());
      ans = min(ans, choice[0]);
    }
    for (int i = 0; i < v[2].size(); i++) {
      auto green2 = lower_bound(v[1].begin(), v[1].end(), v[2][i]);
      auto green1 = green2;
      green1--;
      if (green2 == v[1].end())
        green2 = green1;
      else if (green2 == v[1].begin())
        green1 = green2;
      auto blue22 = lower_bound(v[0].begin(), v[0].end(), *green2);
      auto blue21 = blue22;
      blue21--;
      if (blue22 == v[0].end())
        blue22 = blue21;
      else if (blue22 == v[0].begin())
        blue21 = blue22;
      auto blue12 = lower_bound(v[0].begin(), v[0].end(), *green1);
      auto blue11 = blue12;
      blue11--;
      if (blue12 == v[0].end())
        blue12 = blue11;
      else if (blue12 == v[0].begin())
        blue11 = blue12;
      vector<long long> choice;
      choice.push_back(((v[2][i] - (*green2)) * (v[2][i] - (*green2))) +
                       ((v[2][i] - (*blue22)) * (v[2][i] - (*blue22))) +
                       (((*green2) - (*blue22)) * ((*green2) - (*blue22))));
      choice.push_back(((v[2][i] - (*green2)) * (v[2][i] - (*green2))) +
                       ((v[2][i] - (*blue21)) * (v[2][i] - (*blue21))) +
                       (((*green2) - (*blue21)) * ((*green2) - (*blue21))));
      choice.push_back(((v[2][i] - (*green1)) * (v[2][i] - (*green1))) +
                       ((v[2][i] - (*blue12)) * (v[2][i] - (*blue12))) +
                       (((*green1) - (*blue12)) * ((*green1) - (*blue12))));
      choice.push_back(((v[2][i] - (*green1)) * (v[2][i] - (*green1))) +
                       ((v[2][i] - (*blue11)) * (v[2][i] - (*blue11))) +
                       (((*green1) - (*blue11)) * ((*green1) - (*blue11))));
      sort(choice.begin(), choice.end());
      ans = min(ans, choice[0]);
    }
    cout << ans << '\n';
  }
  return 0;
}
