//prewritten code: https://github.com/antma/algo
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;

final class InputReader {
  private:
  ubyte[] p, buffer;
  bool eof;
  bool rawRead () {
    if (eof) {
      return false;
    }
    p = stdin.rawRead (buffer);
    if (p.empty) {
      eof = true;
      return false;
    }
    return true;
  }
  ubyte nextByte(bool check) () {
    static if (check) {
      if (p.empty) {
        if (!rawRead ()) {
          return 0;
        }
      }
    }
    auto r = p.front;
    p.popFront ();
    return r;
  }
  public:
  this () {
    buffer = uninitializedArray!(ubyte[])(16<<20);
  }
  bool seekByte (in ubyte lo) {
    while (true) {
      p = p.find! (c => c >= lo);
      if (!p.empty) {
        return false;
      }
      if (!rawRead ()) {
        return true;
      }
    }
  }
  template next(T) if (isSigned!T) {
    T next ()  {
      if (seekByte (45)) {
        return 0;
      }
      T res;
      ubyte b = nextByte!false ();
      if (b == 45) {
        while (true) {
          b = nextByte!true ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 - (b - 48);
        }
      } else {
        res = b - 48;
        while (true) {
          b = nextByte!true ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 + (b - 48);
        }
      }
    }
  }
  template next(T) if (isUnsigned!T) {
    T next () {
      if (seekByte (48)) {
        return 0;
      }
      T res = nextByte!false () - 48;
      while (true) {
        ubyte b = nextByte!true ();
        if (b < 48 || b >= 58) {
          break;
        }
        res = res * 10 + (b - 48);
      }
      return res;
    }
  }
  T[] nextA(T) (in int n) {
    auto a = uninitializedArray!(T[]) (n);
    foreach (i; 0 .. n) {
      a[i] = next!T;
    }
    return a;
  }
}

void main() {
  auto r = new InputReader ();
  immutable nt = r.next!uint ();
  int[] ra (int n) {
    auto a = r.nextA!int (n);
    sort (a);
    return a;
  }
  foreach (tid; 0 .. nt) {
    long res = long.max;
    auto a = r.nextA!uint (3);
    auto t = new int[][3];
    foreach (k; 0 .. 3) t[k] = ra (a[k]);
    void check (long u, long v, long w) {
      long q = (u - v) * (u - v);
      q += (u - w) * (u - w);
      q += (v - w) * (v - w);
      if (res > q) res = q;
    }
    void f (in int[] x, in int[] y, in int[] z) {
      size_t j, k;
      foreach (i; 0 .. x.length) {
        int xv = x[i];
        while (j < y.length && y[j] < xv) ++j; 
        while (k < z.length && z[k] < xv) ++k; 
        void go (size_t u, size_t v) {
          if (u < y.length && v < z.length)
            check (xv, y[u], z[v]);
        }
        go (j, k);
        if (k > 0) {
          go (j, k - 1);
        }
        if (j > 0) {
          go (j - 1, k);
          if (k > 0) {
            go (j - 1, k - 1);
          }
        }
      }
    }
    f (t[0], t[1], t[2]);
    f (t[1], t[0], t[2]);
    f (t[2], t[0], t[1]);
    writeln (res);
  }
}

