#include <bits/stdc++.h>
uint32_t readu32() {
  int c;
  while ((c = getchar_unlocked()) < '0')
    ;
  uint32_t n = c & 15U;
  while ((c = getchar_unlocked()) >= '0') n = n * 10 + (c & 15U);
  return n;
}
uint64_t readu64() {
  int c;
  while ((c = getchar_unlocked()) < '0')
    ;
  uint64_t n = c & 15U;
  while ((c = getchar_unlocked()) >= '0') n = n * 10 + (c & 15U);
  return n;
}
int32_t read32() {
  int c;
  while ((c = getchar_unlocked()) < '-')
    ;
  bool neg = c == '-';
  if (neg) c = getchar_unlocked();
  uint32_t n = c & 15U;
  while ((c = getchar_unlocked()) >= '0') n = n * 10 + (c & 15U);
  return neg ? -(int32_t)n : n;
}
int64_t read64() {
  int c;
  while ((c = getchar_unlocked()) < '-')
    ;
  bool neg = c == '-';
  if (neg) c = getchar_unlocked();
  uint64_t n = c & 15;
  while ((c = getchar_unlocked()) >= '0') n = n * 10 + (c & 15U);
  return neg ? -(int64_t)n : n;
}
template <typename Cont, typename... Cmp>
void sortc(Cont& cont, Cmp&&... cmp) {
  using std::begin;
  using std::end;
  std::sort(begin(cont), end(cont), cmp...);
}
template <typename T, typename U>
void minup(T& min, U&& val) {
  if (val < min) min = val;
}
template <typename T, typename U>
void maxup(T& max, U&& val) {
  if (val > max) max = val;
}
template <typename T>
T myabs(T x) {
  return x < 0 ? -x : x;
}
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  const int per[][4] = {{0, 1, 2, 3}, {0, 1, 3, 2}, {0, 2, 1, 3}, {0, 2, 3, 1},
                        {0, 3, 1, 2}, {0, 3, 2, 1}, {1, 0, 2, 3}, {1, 0, 3, 2},
                        {1, 2, 0, 3}, {1, 2, 3, 0}, {1, 3, 0, 2}, {1, 3, 2, 0},
                        {2, 0, 1, 3}, {2, 0, 3, 1}, {2, 1, 0, 3}, {2, 1, 3, 0},
                        {2, 3, 0, 1}, {2, 3, 1, 0}, {3, 0, 1, 2}, {3, 0, 2, 1},
                        {3, 1, 0, 2}, {3, 1, 2, 0}, {3, 2, 0, 1}, {3, 2, 1, 0}};
  int t = (readu32());
  while (t--) {
    int x[4][2];
    for (int i = 0; i < 4; i++)
      for (int j = 0; j < 2; j++) x[i][j] = (read32());
    int dmin = 1 << 30;
    int xo[4][2];
    for (const int* p : per) {
      int xx[4][2];
      for (int i = 0; i < 4; i++)
        for (int j = 0; j < 2; j++) xx[i][j] = x[p[i]][j];
      int axs[4];
      for (axs[0] = 0; axs[0] < 2; axs[0]++)
        for (axs[1] = 0; axs[1] < 2; axs[1]++)
          for (axs[2] = 0; axs[2] < 2; axs[2]++)
            for (axs[3] = 0; axs[3] < 2; axs[3]++) {
              const int NONE = 1 << 30;
              const int side[4][2]{{0, 0}, {0, 1}, {1, 0}, {1, 1}};
              int b[2][2]{{NONE, NONE}, {NONE, NONE}};
              int len = NONE;
              int maxmove = 0;
              for (int i = 4; i--;) {
                int axfix = axs[i] ^ 1;
                int& bnd = b[axfix][side[i][axfix]];
                if (bnd == NONE)
                  bnd = xx[i][axfix];
                else if (bnd != xx[i][axfix])
                  goto next;
              }
              for (int ax : {0, 1}) {
                if (b[ax][0] != NONE && b[ax][1] != NONE) {
                  int len2 = b[ax][1] - b[ax][0];
                  if (len2 <= 0) goto next;
                  if (len == NONE)
                    len = len2;
                  else if (len != len2)
                    goto next;
                }
              }
              for (int ax : {0, 1}) {
                if (b[ax][0] == NONE && b[ax][1] == NONE) {
                  int z[2][2]{{xx[0][ax], xx[1 + ax][ax]},
                              {xx[2 - ax][ax], xx[3][ax]}};
                  int e[]{z[0][0] + z[0][1], z[1][0] + z[1][1]};
                  int near = (e[1] >> 1) - (e[0] + 1 >> 1);
                  int far = (e[1] + 1 >> 1) - (e[0] >> 1);
                  int eqcost[]{(myabs(z[0][1] - z[0][0]) + 1) / 2,
                               (myabs(z[1][1] - z[1][0]) + 1) / 2};
                  if (len > near && len < far) {
                    b[ax][0] = e[0] >> 1;
                    b[ax][1] = e[1] >> 1;
                  } else {
                    int dist = len < near ? near : far;
                    int cdif = myabs(eqcost[1] - eqcost[0]);
                    int lendif = myabs(len - dist);
                    int u = min(cdif, lendif);
                    if (len <= near) {
                      b[ax][0] = (e[0] + 1) >> 1;
                      b[ax][1] = e[1] >> 1;
                      if (eqcost[0] > eqcost[1])
                        b[ax][1] -= u;
                      else
                        b[ax][0] += u;
                      lendif -= u;
                      b[ax][0] += lendif / 2;
                      b[ax][1] -= (lendif + 1) / 2;
                    } else {
                      b[ax][0] = e[0] >> 1;
                      b[ax][1] = (e[1] + 1) >> 1;
                      if (eqcost[0] > eqcost[1])
                        b[ax][1] += u;
                      else
                        b[ax][0] -= u;
                      lendif -= u;
                      b[ax][0] -= lendif / 2;
                      b[ax][1] += (lendif + 1) / 2;
                    }
                    lendif -= u;
                  }
                } else if (b[ax][0] == NONE) {
                  b[ax][0] = b[ax][1] - len;
                } else if (b[ax][1] == NONE) {
                  b[ax][1] = b[ax][0] + len;
                }
                for (int i = 4; i--;)
                  maxup(maxmove, myabs(xx[i][ax] - b[ax][side[i][ax]]));
              }
              if (maxmove < dmin) {
                dmin = maxmove;
                for (int i = 4; i--;)
                  for (int j = 2; j--;) xo[p[i]][j] = b[j][side[i][j]];
              }
            next:;
            }
    }
    if (dmin == (1 << 30)) {
      printf("-1\n");
    } else {
      printf("%d\n", dmin);
      for (int i = 0; i < 4; i++) {
        printf("%d %d\n", xo[i][0], xo[i][1]);
      }
    }
  }
  return 0;
}
