#include <bits/stdc++.h>
using namespace std;
FILE* in;
FILE* out;
const int MAX = 1024;
const int INF = 1000000001;
struct Point {
  int x, y;
  Point(int x_ = 0, int y_ = 0) : x(x_), y(y_) {}
};
Point a[4];
Point ans[4];
int bestPlace(int p1, int p2, int p3, int p4, int dist) {
  int best = INF, with = 0;
  int left = -100000000, right = +100000000;
  while (left <= right) {
    int m1 = left + (right - left) / 3;
    int m2 = right - (right - left) / 3;
    int c1 = max(abs(p1 - m1), max(abs(p2 - (m1 + dist)),
                                   max(abs(p3 - m1), abs(p4 - (m1 + dist)))));
    int c2 = max(abs(p1 - m2), max(abs(p2 - (m2 + dist)),
                                   max(abs(p3 - m2), abs(p4 - (m2 + dist)))));
    if (best > c1) best = c1, with = m1;
    if (best > c2) best = c2, with = m2;
    c1 < c2 ? right = m2 - 1 : left = m1 + 1;
  }
  return with;
}
int matchDist(const Point& p1, const Point& p2) {
  if (p1.x == p2.x) return abs(p1.y - p2.y);
  if (p1.y == p2.y) return abs(p1.x - p2.x);
  return INF;
}
int bestMatch(int x1, int x2, int y1, int y2, bool update) {
  Point p1 = Point(x1, y1);
  Point p2 = Point(x1, y2);
  Point p3 = Point(x2, y1);
  Point p4 = Point(x2, y2);
  int best = INF;
  vector<int> v = {0, 1, 2, 3};
  do {
    int cur = 0;
    cur = max(cur, matchDist(a[v[0]], p1));
    cur = max(cur, matchDist(a[v[1]], p2));
    cur = max(cur, matchDist(a[v[2]], p3));
    cur = max(cur, matchDist(a[v[3]], p4));
    if (best > cur) {
      best = cur;
      if (update) {
        ans[v[0]] = p1;
        ans[v[1]] = p2;
        ans[v[2]] = p3;
        ans[v[3]] = p4;
      }
    }
  } while (next_permutation(v.begin(), v.end()));
  return best;
}
int eval(int mask, bool update) {
  int hor[4];
  for (int i = 0; i < 4; i++) hor[i] = !!(mask & (1 << i));
  map<int, int> x, y;
  int numHor = 0, numVer = 0;
  for (int i = 0; i < 4; i++) {
    if (hor[i] == 0) x[a[i].x]++, numVer++;
    if (hor[i] == 1) y[a[i].y]++, numHor++;
  }
  if (numHor == 0) {
    if ((int)x.size() != 2) return INF;
    auto it = x.begin();
    if (it->second != 2) return INF;
    int x1 = it->first;
    it++;
    if (it->second != 2) return INF;
    int x2 = it->first;
    int pos[4], idx = 0;
    for (int i = 0; i < 4; i++)
      if (a[i].x == x1) pos[idx++] = a[i].y;
    for (int i = 0; i < 4; i++)
      if (a[i].x == x2) pos[idx++] = a[i].y;
    if (pos[0] > pos[1]) swap(pos[0], pos[1]);
    if (pos[2] > pos[3]) swap(pos[2], pos[3]);
    int dist = x2 - x1;
    int y1 = bestPlace(pos[0], pos[1], pos[2], pos[3], dist);
    return bestMatch(x1, x2, y1, y1 + dist, update);
  }
  if (numHor == 1) {
    if ((int)x.size() != 2) return INF;
    auto it = x.begin();
    int x1 = it->first;
    it++;
    int x2 = it->first;
    it = y.begin();
    int y1 = it->first;
    int dist = x2 - x1;
    int best = INF;
    int cur1 = bestMatch(x1, x2, y1, y1 + dist, false);
    if (best > cur1) best = bestMatch(x1, x2, y1, y1 + dist, update);
    int cur2 = bestMatch(x1, x2, y1 - dist, y1, false);
    if (best > cur2) best = bestMatch(x1, x2, y1 - dist, y1, update);
    return best;
  }
  if (numHor == 2) {
    if ((int)x.size() != 2 && (int)y.size() != 2) return INF;
    auto itx = x.begin();
    int x1 = itx->first;
    itx++;
    int x2 = itx == x.end() ? x1 : itx->first;
    auto ity = y.begin();
    int y1 = ity->first;
    ity++;
    int y2 = ity == y.end() ? y1 : ity->first;
    int distx = x2 - x1, disty = y2 - y1;
    if (distx != 0 && disty != 0 && distx != disty) return INF;
    int best = INF;
    if (distx != 0 && disty != 0) {
      best = min(best, bestMatch(x1, x2, y1, y2, update));
    } else if (distx == 0) {
      int cur1 = bestMatch(x1, x1 + disty, y1, y2, false);
      if (best > cur1) best = bestMatch(x1, x1 + disty, y1, y2, update);
      int cur2 = bestMatch(x1 - disty, x1, y1, y2, false);
      if (best > cur2) best = bestMatch(x1 - disty, x1, y1, y2, update);
    } else {
      int cur1 = bestMatch(x1, x2, y1, y1 + distx, false);
      if (best > cur1) best = bestMatch(x1, x2, y1, y1 + distx, update);
      int cur2 = bestMatch(x1, x2, y1 - distx, y1, false);
      if (best > cur2) best = bestMatch(x1, x2, y1 - distx, y1, update);
    }
    return best;
  }
  if (numHor == 3) {
    if ((int)y.size() != 2) return INF;
    auto ity = y.begin();
    int y1 = ity->first;
    ity++;
    int y2 = ity->first;
    auto itx = x.begin();
    int x1 = itx->first;
    int dist = y2 - y1;
    int best = INF;
    int cur1 = bestMatch(x1, x1 + dist, y1, y2, false);
    if (best > cur1) best = bestMatch(x1, x1 + dist, y1, y2, update);
    int cur2 = bestMatch(x1 - dist, x1, y1, y2, false);
    if (best > cur2) best = bestMatch(x1 - dist, x1, y1, y2, update);
    return best;
  }
  if (numHor == 4) {
    if ((int)y.size() != 2) return INF;
    auto it = y.begin();
    if (it->second != 2) return INF;
    int y1 = it->first;
    it++;
    if (it->second != 2) return INF;
    int y2 = it->first;
    int pos[4], idx = 0;
    for (int i = 0; i < 4; i++)
      if (a[i].y == y1) pos[idx++] = a[i].x;
    for (int i = 0; i < 4; i++)
      if (a[i].y == y2) pos[idx++] = a[i].x;
    if (pos[0] > pos[1]) swap(pos[0], pos[1]);
    if (pos[2] > pos[3]) swap(pos[2], pos[3]);
    int dist = y2 - y1;
    int x1 = bestPlace(pos[0], pos[1], pos[2], pos[3], dist);
    return bestMatch(x1, x1 + dist, y1, y2, update);
  }
  return INF;
}
void solve() {
  int best = INF, with = -1;
  for (int mask = 0; mask < (1 << 4); mask++) {
    int cur = eval(mask, false);
    if (best > cur) best = cur, with = mask;
  }
  if (with == -1) {
    fprintf(out, "-1\n");
    return;
  }
  eval(with, true);
  fprintf(out, "%d\n", best);
  for (int i = 0; i < 4; i++) fprintf(out, "%d %d\n", ans[i].x, ans[i].y);
}
int main(void) {
  in = stdin;
  out = stdout;
  int numTests;
  fscanf(in, "%d", &numTests);
  for (int test = 0; test < numTests; test++) {
    for (int i = 0; i < 4; i++) fscanf(in, "%d %d", &a[i].x, &a[i].y);
    solve();
  }
  return 0;
}
