#include <bits/stdc++.h>
using namespace std;
inline int ri() {
  int x;
  scanf("%d", &x);
  return x;
}
template <typename T>
inline bool smax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool smin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
struct point {
  int x, y;
  point(int x = 0, int y = 0) : x(x), y(y) {}
  point operator+(point a) { return point(x + a.x, y + a.y); }
  point operator-(point a) { return point(x - a.x, y - a.y); }
  point operator*(int t) { return point(x * t, y * t); }
};
pair<int, vector<point>> FAIL(-1, {});
vector<point> complete(vector<point> p, bool fx[4]) {
  for (int i = 0; i < (4); i++)
    if (fx[i])
      for (int j = 0; j < (4); j++)
        if (j != i && fx[j]) {
          auto d = p[j] - p[i];
          int g = -1;
          if ((i & 1) != (j & 1)) {
            g = d.x * ((j & 1) - (i & 1));
          }
          if ((i >> 1) != (j >> 1)) {
            g = d.y * ((j >> 1) - (i >> 1));
          }
          if (g > 0) {
            for (int a = 0; a < (4); a++)
              if (!fx[a]) {
                for (int b = 0; b < (4); b++)
                  if (fx[b]) {
                    p[a] = point(p[b].x - ((b & 1) - (a & 1)) * g,
                                 p[b].y - ((b >> 1) - (a >> 1)) * g);
                    fx[a] = 1;
                  }
              }
            return p;
          }
          return {};
        }
  return {};
}
pair<int, vector<point>> check(vector<point> p, vector<point> res) {
  if (res.size() != 4) return FAIL;
  for (int i = 0; i < (4); i++)
    if (res[i].y != res[i ^ 1].y || res[i].x != res[i ^ 2].x) return FAIL;
  if (res[1].x - res[0].x != res[2].y - res[0].y || res[1].x - res[0].x == 0)
    return FAIL;
  int t = 0;
  for (int i = 0; i < (4); i++)
    if (res[i].x != p[i].x && res[i].y != p[i].y) return FAIL;
  for (int i = 0; i < (4); i++)
    smax(t, abs(res[i].x - p[i].x) + abs(res[i].y - p[i].y));
  return make_pair(t, res);
}
pair<int, vector<point>> slide(vector<point> p) {
  if (p[0].y != p[1].y || p[2].y != p[3].y) return FAIL;
  int g = p[2].y - p[0].y;
  if (g <= 0) return FAIL;
  int l = 0, r = 1e9;
  while (l < r) {
    int m = (l + r) / 2, ok = true;
    int lx = max(p[0].x, p[2].x) - m, rx = min(p[0].x, p[2].x) + m;
    int ly = max(p[1].x, p[3].x) - m, ry = min(p[1].x, p[3].x) + m;
    if (lx > rx || ly > ry || ly - rx > g || ry - lx < g) ok = false;
    if (ok)
      r = m;
    else
      l = m + 1;
  }
  int lx = max(p[0].x, p[2].x) - l, rx = min(p[0].x, p[2].x) + r;
  int ly = max(p[1].x, p[3].x) - l, ry = min(p[1].x, p[3].x) + r;
  int lt, rt;
  if (lx + g >= ly && lx + g <= ry)
    lt = lx, rt = lx + g;
  else if (rx + g >= ly && rx + g <= ry)
    lt = rx, rt = rx + g;
  else if (lx <= ly - g && ly - g <= rx)
    lt = ly - g, rt = ly;
  else
    lt = ry - g, rt = ry;
  auto res = p;
  res[0].x = res[2].x = lt;
  res[1].x = res[3].x = rt;
  return check(p, res);
}
pair<int, vector<point>> work(vector<point> p, vector<int> d) {
  bool fx[4] = {0};
  vector<point> fp(4);
  bool fixed = false;
  for (int i = 0; i < (4); i++) {
    if (d[i] != d[i ^ 1] && d[i] == 1) {
      fp[i] = point(p[i].x, p[i ^ 1].y);
      fx[i] = 1;
    }
    if (d[i] != d[i ^ 2] && d[i] == 0) {
      fp[i] = point(p[i ^ 2].x, p[i].y);
      fx[i] = 1;
    }
  }
  for (int i = 0; i < (4); i++)
    if (fx[i]) fixed = true;
  if (fixed) {
    return check(p, complete(fp, fx));
  }
  if (d[0] == 0) {
    return slide(p);
  } else {
    for (int i = 0; i < (4); i++) swap(p[i].x, p[i].y);
    swap(p[1], p[2]);
    auto res = slide(p);
    for (auto &x : res.second) swap(x.x, x.y);
    if (res.second.size()) swap((res.second)[1], (res.second)[2]);
    return res;
  }
}
void solve() {
  vector<point> v(4);
  for (int i = 0; i < (4); i++) cin >> v[i].x >> v[i].y;
  int ord[] = {0, 1, 2, 3};
  pair<int, vector<point>> res(-1, {});
  do {
    vector<point> p(4);
    for (int i = 0; i < (4); i++) p[i] = v[ord[i]];
    vector<int> d(4);
    for (d[0] = 0; d[0] < 2; d[0]++)
      for (d[1] = 0; d[1] < 2; d[1]++)
        for (d[2] = 0; d[2] < 2; d[2]++)
          for (d[3] = 0; d[3] < 2; d[3]++) {
            auto tmp = work(p, d);
            if (tmp.second.size()) {
              vector<point> vs(4);
              for (int i = 0; i < (4); i++) vs[ord[i]] = (tmp.second)[i];
              tmp.second = vs;
            }
            if (tmp.first >= 0) {
              if (res.first < 0 || smin(res.first, tmp.first)) res = tmp;
            }
          }
  } while (next_permutation(ord, ord + 4));
  cout << res.first << endl;
  for (auto x : res.second) cout << x.x << ' ' << x.y << '\n';
}
int main() {
  int Q = ri();
  for (int i = 0; i < (Q); i++) {
    solve();
  }
  return 0;
}
