#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n1, n2, n3;
    cin >> n1 >> n2 >> n3;
    vector<long long> v1(n1);
    vector<long long> v2(n2);
    vector<long long> v3(n3);
    for (int i = 0; i < n1; i++) {
      cin >> v1[i];
    }
    for (int i = 0; i < n2; i++) {
      cin >> v2[i];
    }
    for (int i = 0; i < n3; i++) {
      cin >> v3[i];
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    sort(v3.begin(), v3.end());
    long long ans = 5e18 + 7;
    for (int i = 0; i < n1; i++) {
      int l = -1, r = n2;
      while (r - l > 1) {
        int mid = (r + l) / 2;
        if (v2[mid] <= v1[i])
          l = mid;
        else
          r = mid;
      }
      long long min1 = (l == -1 ? -1 : v2[l]);
      l = -1;
      r = n2;
      while (r - l > 1) {
        int mid = (r + l) / 2;
        if (v2[mid] >= v1[i])
          r = mid;
        else
          l = mid;
      }
      long long max1 = (r == n2 ? -1 : v2[r]);
      l = -1, r = n3;
      while (r - l > 1) {
        int mid = (r + l) / 2;
        if (v3[mid] <= v1[i])
          l = mid;
        else
          r = mid;
      }
      long long min2 = (l == -1 ? -1 : v3[l]);
      l = -1;
      r = n3;
      while (r - l > 1) {
        int mid = (r + l) / 2;
        if (v3[mid] >= v1[i])
          r = mid;
        else
          l = mid;
      }
      long long max2 = (r == n3 ? -1 : v3[r]);
      if (min1 > -1 && min2 > -1) {
        ans = min(ans, (v1[i] - min1) * (v1[i] - min1) +
                           (v1[i] - min2) * (v1[i] - min2) +
                           (min1 - min2) * (min1 - min2));
      }
      if (max1 > -1 && max2 > -1) {
        ans = min(ans, (v1[i] - max1) * (v1[i] - max1) +
                           (v1[i] - max2) * (v1[i] - max2) +
                           (max1 - max2) * (max1 - max2));
      }
      if (min1 > -1 && max2 > -1) {
        ans = min(ans, (v1[i] - min1) * (v1[i] - min1) +
                           (v1[i] - max2) * (v1[i] - max2) +
                           (min1 - max2) * (min1 - max2));
      }
      if (max1 > -1 && min2 > -1) {
        ans = min(ans, (v1[i] - max1) * (v1[i] - max1) +
                           (v1[i] - min2) * (v1[i] - min2) +
                           (max1 - min2) * (max1 - min2));
      }
    }
    for (int i = 0; i < n2; i++) {
      int l = -1, r = n1;
      while (r - l > 1) {
        int mid = (r + l) / 2;
        if (v1[mid] <= v2[i])
          l = mid;
        else
          r = mid;
      }
      long long min1 = (l == -1 ? -1 : v1[l]);
      l = -1;
      r = n1;
      while (r - l > 1) {
        int mid = (r + l) / 2;
        if (v1[mid] >= v2[i])
          r = mid;
        else
          l = mid;
      }
      long long max1 = (r == n1 ? -1 : v1[r]);
      l = -1, r = n3;
      while (r - l > 1) {
        int mid = (r + l) / 2;
        if (v3[mid] <= v2[i])
          l = mid;
        else
          r = mid;
      }
      long long min2 = (l == -1 ? -1 : v3[l]);
      l = -1;
      r = n3;
      while (r - l > 1) {
        int mid = (r + l) / 2;
        if (v3[mid] >= v2[i])
          r = mid;
        else
          l = mid;
      }
      long long max2 = (r == n3 ? -1 : v3[r]);
      if (min1 > -1 && min2 > -1) {
        ans = min(ans, (v2[i] - min1) * (v2[i] - min1) +
                           (v2[i] - min2) * (v2[i] - min2) +
                           (min1 - min2) * (min1 - min2));
      }
      if (max1 > -1 && max2 > -1) {
        ans = min(ans, (v2[i] - max1) * (v2[i] - max1) +
                           (v2[i] - max2) * (v2[i] - max2) +
                           (max1 - max2) * (max1 - max2));
      }
      if (min1 > -1 && max2 > -1) {
        ans = min(ans, (v2[i] - min1) * (v2[i] - min1) +
                           (v2[i] - max2) * (v2[i] - max2) +
                           (min1 - max2) * (min1 - max2));
      }
      if (max1 > -1 && min2 > -1) {
        ans = min(ans, (v2[i] - max1) * (v2[i] - max1) +
                           (v2[i] - min2) * (v2[i] - min2) +
                           (max1 - min2) * (max1 - min2));
      }
    }
    for (int i = 0; i < n3; i++) {
      int l = -1, r = n2;
      while (r - l > 1) {
        int mid = (r + l) / 2;
        if (v2[mid] <= v3[i])
          l = mid;
        else
          r = mid;
      }
      long long min1 = (l == -1 ? -1 : v2[l]);
      l = -1;
      r = n2;
      while (r - l > 1) {
        int mid = (r + l) / 2;
        if (v2[mid] >= v3[i])
          r = mid;
        else
          l = mid;
      }
      long long max1 = (r == n2 ? -1 : v2[r]);
      l = -1, r = n1;
      while (r - l > 1) {
        int mid = (r + l) / 2;
        if (v1[mid] <= v3[i])
          l = mid;
        else
          r = mid;
      }
      long long min2 = (l == -1 ? -1 : v1[l]);
      l = -1;
      r = n1;
      while (r - l > 1) {
        int mid = (r + l) / 2;
        if (v1[mid] >= v3[i])
          r = mid;
        else
          l = mid;
      }
      long long max2 = (r == n1 ? -1 : v1[r]);
      if (min1 > -1 && min2 > -1) {
        ans = min(ans, (v3[i] - min1) * (v3[i] - min1) +
                           (v3[i] - min2) * (v3[i] - min2) +
                           (min1 - min2) * (min1 - min2));
      }
      if (max1 > -1 && max2 > -1) {
        ans = min(ans, (v3[i] - max1) * (v3[i] - max1) +
                           (v3[i] - max2) * (v3[i] - max2) +
                           (max1 - max2) * (max1 - max2));
      }
      if (min1 > -1 && max2 > -1) {
        ans = min(ans, (v3[i] - min1) * (v3[i] - min1) +
                           (v3[i] - max2) * (v3[i] - max2) +
                           (min1 - max2) * (min1 - max2));
      }
      if (max1 > -1 && min2 > -1) {
        ans = min(ans, (v3[i] - max1) * (v3[i] - max1) +
                           (v3[i] - min2) * (v3[i] - min2) +
                           (max1 - min2) * (max1 - min2));
      }
    }
    cout << ans << "\n";
  }
}
