#include <bits/stdc++.h>
using ll = long long;
constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acosl(-1.0L);
using namespace std;
void scans(string& str) {
  char c;
  str = "";
  scanf("%c", &c);
  if (c == '\n') scanf("%c", &c);
  while (c != '\n' && c != -1 && c != ' ') {
    str += c;
    scanf("%c", &c);
  }
}
void scanc(char& str) {
  char c;
  scanf("%c", &c);
  if (c == -1) return;
  while (c == '\n') {
    scanf("%c", &c);
  }
  str = c;
}
double acot(double x) { return PI / 2 - atan(x); }
ll LSB(ll n) { return (n & (-n)); }
ll p(ll a) { return a * a; }
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int r, g, b;
    scanf("%d%d%d", &r, &g, &b);
    vector<int> R(r), G(g), B(b);
    for (int i = 0; i < (r); ++i) scanf("%d", &R[i]);
    for (int i = 0; i < (g); ++i) scanf("%d", &G[i]);
    for (int i = 0; i < (b); ++i) scanf("%d", &B[i]);
    sort((R).begin(), (R).end());
    sort((G).begin(), (G).end());
    sort((B).begin(), (B).end());
    ll ans = LINF;
    for (int i = 0; i < (r); ++i) {
      auto itegreen1 = lower_bound((G).begin(), (G).end(), R[i]),
           iteblue1 = lower_bound((B).begin(), (B).end(), R[i]);
      ll green1 = -1;
      if (itegreen1 != G.end())
        green1 = *itegreen1;
      else
        green1 = G[G.size() - 1];
      if (itegreen1 != G.begin()) --itegreen1;
      ll green2 = -1;
      if (itegreen1 != G.begin())
        green2 = *itegreen1;
      else
        green2 = G[0];
      ll blue1 = -1;
      if (iteblue1 != B.end())
        blue1 = *iteblue1;
      else
        blue1 = B[B.size() - 1];
      if (iteblue1 != B.begin()) --iteblue1;
      ll blue2 = -1;
      if (iteblue1 != B.begin())
        blue2 = *iteblue1;
      else
        blue2 = B[0];
      ans =
          min<ll>({(green1 != -1 and blue1 != -1)
                       ? p(green1 - R[i]) + p(R[i] - blue1) + p(blue1 - green1)
                       : LINF,
                   (green2 != -1 and blue1 != -1)
                       ? p(green2 - R[i]) + p(R[i] - blue1) + p(blue1 - green2)
                       : LINF,
                   (green1 != -1 and blue2 != -1)
                       ? p(green1 - R[i]) + p(R[i] - blue2) + p(blue2 - green1)
                       : LINF,
                   (green2 != -1 and blue2 != -1)
                       ? p(green2 - R[i]) + p(R[i] - blue2) + p(blue2 - green2)
                       : LINF,
                   ans});
    }
    for (int i = 0; i < (g); ++i) {
      auto itered1 = lower_bound((R).begin(), (R).end(), G[i]),
           iteblue1 = lower_bound((B).begin(), (B).end(), G[i]);
      ll red1 = -1;
      if (itered1 != R.end())
        red1 = *itered1;
      else
        red1 = R[R.size() - 1];
      if (itered1 != R.begin()) --itered1;
      ll red2 = -1;
      if (itered1 != R.begin())
        red2 = *itered1;
      else
        red2 = R[0];
      ll blue1 = -1;
      if (iteblue1 != B.end())
        blue1 = *iteblue1;
      else
        blue1 = B[B.size() - 1];
      if (iteblue1 != B.begin()) --iteblue1;
      ll blue2 = -1;
      if (iteblue1 != B.begin())
        blue2 = *iteblue1;
      else
        blue2 = B[0];
      ans = min<ll>({(red1 != -1 and blue1 != -1)
                         ? p(red1 - G[i]) + p(G[i] - blue1) + p(blue1 - red1)
                         : LINF,
                     (red2 != -1 and blue1 != -1)
                         ? p(red2 - G[i]) + p(G[i] - blue1) + p(blue1 - red2)
                         : LINF,
                     (red1 != -1 and blue2 != -1)
                         ? p(red1 - G[i]) + p(G[i] - blue2) + p(blue2 - red1)
                         : LINF,
                     (red2 != -1 and blue2 != -1)
                         ? p(red2 - G[i]) + p(G[i] - blue2) + p(blue2 - red2)
                         : LINF,
                     ans});
    }
    for (int i = 0; i < (b); ++i) {
      auto itered1 = lower_bound((R).begin(), (R).end(), B[i]),
           itegreen1 = lower_bound((G).begin(), (G).end(), B[i]);
      ll green1 = -1;
      if (itegreen1 != G.end())
        green1 = *itegreen1;
      else
        green1 = G[G.size() - 1];
      if (itegreen1 != G.begin()) --itegreen1;
      ll green2 = -1;
      if (itegreen1 != G.begin())
        green2 = *itegreen1;
      else
        green2 = G[0];
      ll red1 = -1;
      if (itered1 != R.end())
        red1 = *itered1;
      else
        red1 = R[R.size() - 1];
      if (itered1 != R.begin()) --itered1;
      ll red2 = -1;
      if (itered1 != R.begin())
        red2 = *itered1;
      else
        red2 = R[0];
      ans = min<ll>({(red1 != -1 and green1 != -1)
                         ? p(red1 - B[i]) + p(B[i] - green1) + p(green1 - red1)
                         : LINF,
                     (red2 != -1 and green1 != -1)
                         ? p(red2 - B[i]) + p(B[i] - green1) + p(green1 - red2)
                         : LINF,
                     (red1 != -1 and green2 != -1)
                         ? p(red1 - B[i]) + p(B[i] - green2) + p(green2 - red1)
                         : LINF,
                     (red2 != -1 and green2 != -1)
                         ? p(red2 - B[i]) + p(B[i] - green2) + p(green2 - red2)
                         : LINF,
                     ans});
    }
    printf("%lld\n", ans);
  }
  return 0;
}
