#include <bits/stdc++.h>
using namespace std;
namespace fastIO {
template <typename T>
void rd(T &x) {
  T y = 0;
  T f = 1;
  double d = 1.0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -f;
    c = getchar();
  }
  while (c >= '0' && c <= '9') y = y * 10 + c - '0', c = getchar();
  if (c == '.') {
    c = getchar();
    while (c <= '9' && c >= '0') y += d * (c ^ 48), d *= 0.1, c = getchar();
  }
  x = y * f;
}
template <typename T, typename... Args>
inline void rd(T &t, Args &...args) {
  rd(t);
  rd(args...);
}
}  // namespace fastIO
using namespace fastIO;
int ans = 1000000000;
bool mrk[4];
struct point {
  int x, y, id;
} a[4], Ans[4], tmp[4];
void update() {
  int per[4] = {0, 1, 2, 3};
  do {
    bool can = 1;
    int res = 0;
    for (int i = (0); i <= (3); ++i) {
      if (a[i].y == tmp[per[i]].y)
        res = max(res, abs(tmp[per[i]].x - a[i].x));
      else if (a[i].x == tmp[per[i]].x)
        res = max(res, abs(tmp[per[i]].y - a[i].y));
      else
        can = 0;
    }
    if (!can) continue;
    if (res < ans) {
      ans = res;
      for (int i = (0); i <= (3); ++i) Ans[i] = tmp[per[i]];
    }
  } while (next_permutation(per, per + 4));
}
void calc1() {
  int t[2][4] = {{0, 0, 0, 0}, {0, 0, 0, 0}}, cnt[2] = {0, 0}, _ = 0;
  for (int i = (0); i <= (3); ++i)
    t[mrk[i]][cnt[mrk[i]]++] = (mrk[i] ? a[i].y : a[i].x);
  if (abs(t[1][1] - t[1][0]) != abs(t[0][0] - t[0][1])) return;
  for (int i = (0); i <= (1); ++i)
    for (int j = (0); j <= (1); ++j) tmp[_++] = (point){t[0][i], t[1][j], 0};
  update();
}
void calc2(int id1, int id2, int id3, bool f) {
  int len, pos;
  if (f) {
    len = abs(a[id1].y - a[id2].y);
    tmp[0] = (point){a[id3].x, a[id2].y, 0},
    tmp[1] = (point){a[id3].x, a[id1].y, 0};
    for (int i = (0); i <= (1); ++i) {
      if (i)
        tmp[2] = (point){a[id3].x - len, a[id2].y, 0},
        tmp[3] = (point){a[id3].x - len, a[id1].y, 0};
      else
        tmp[2] = (point){a[id3].x + len, a[id2].y, 0},
        tmp[3] = (point){a[id3].x + len, a[id1].y, 0};
      update();
    }
  } else {
    len = abs(a[id1].x - a[id2].x);
    tmp[0] = (point){a[id1].x, a[id3].y, 0},
    tmp[1] = (point){a[id2].x, a[id3].y, 0};
    for (int i = (0); i <= (1); ++i) {
      if (i)
        tmp[2] = (point){a[id2].x, a[id3].y - len, 0},
        tmp[3] = (point){a[id1].x, a[id3].y - len, 0};
      else
        tmp[2] = (point){a[id2].x, a[id3].y + len, 0},
        tmp[3] = (point){a[id1].x, a[id3].y + len, 0};
      update();
    }
  }
}
bool cmpx(const point &a, const point &b) { return a.x < b.x; }
bool cmpy(const point &a, const point &b) { return a.y < b.y; }
void calc3(bool f) {
  if (f) {
    sort(a, a + 4, cmpy);
    if (a[2].y == a[1].y || a[0].y != a[1].y || a[2].y != a[3].y) return;
    int len = abs(a[2].y - a[1].y);
    for (int i = (0); i <= (1); ++i)
      for (int j = (2); j <= (3); ++j) {
        int mx = -1e9, mn = 1e9;
        a[i].x -= len, a[j].x -= len;
        for (int k = (0); k <= (3); ++k)
          mx = max(mx, a[k].x), mn = min(mn, a[k].x);
        int x0 = (mx + mn) / 2;
        tmp[i] =
            (point){
                x0 + len,
                a[i].y,
                0,
            },
        tmp[j] = (point){x0 + len, a[j].y, 0};
        tmp[i ^ 1] = (point){x0, a[i ^ 1].y, 0},
                tmp[j ^ 1] = (point){x0, a[j ^ 1].y, 0};
        int res = max(abs(mx - x0), abs(mn - x0));
        if (res < ans) {
          ans = res;
          for (int k = (0); k <= (3); ++k) Ans[a[k].id] = tmp[k];
        }
        a[i].x += len, a[j].x += len;
      }
  } else {
    sort(a, a + 4, cmpx);
    if (a[2].x == a[1].x || a[0].x != a[1].x || a[2].x != a[3].x) return;
    int len = abs(a[2].x - a[1].x);
    for (int i = (0); i <= (1); ++i)
      for (int j = (2); j <= (3); ++j) {
        int mx = -1e9, mn = 1e9;
        a[i].y -= len, a[j].y -= len;
        for (int k = (0); k <= (3); ++k)
          mx = max(mx, a[k].y), mn = min(mn, a[k].y);
        int x0 = (mx + mn) / 2;
        tmp[i] = (point){a[i].x, x0 + len, 0},
        tmp[j] = (point){a[j].x, x0 + len, 0};
        tmp[i ^ 1] = (point){a[i ^ 1].x, x0, 0},
                tmp[j ^ 1] = (point){a[j ^ 1].x, x0, 0};
        int res = max(abs(mx - x0), abs(mn - x0));
        if (res < ans) {
          ans = res;
          for (int k = (0); k <= (3); ++k) Ans[a[k].id] = tmp[k];
        }
        a[i].y += len, a[j].y += len;
      }
  }
}
void solve() {
  ans = 1e9;
  for (int i = (0); i <= (3); ++i) rd(a[i].x, a[i].y), a[i].id = i;
  for (int i = (0); i <= (3); ++i)
    for (int j = (i + 1); j <= (3); ++j) {
      mrk[i] = mrk[j] = 1;
      calc1();
      mrk[i] = mrk[j] = 0;
    }
  for (int i = (0); i <= (3); ++i)
    for (int j = (i + 1); j <= (3); ++j)
      for (int k = (0); k <= (3); ++k) {
        if (i != k && j != k) {
          calc2(i, j, k, 0);
          calc2(i, j, k, 1);
        }
      }
  calc3(0);
  calc3(1);
  if (ans == 1000000000)
    puts("-1");
  else {
    printf("%d\n", ans);
    for (int i = (0); i <= (3); ++i) printf("%d %d\n", Ans[i].x, Ans[i].y);
  }
}
int main() {
  int T;
  rd(T);
  while (T--) solve();
}
