#include <bits/stdc++.h>
using namespace std;
template <class T>
using min_queue = priority_queue<T, vector<T>, greater<T>>;
const int INF = static_cast<int>(1e9);
const long long INF_LL = static_cast<long long>(4e18);
const double pi = acos(-1.0);
template <class T>
T& smin(T& x, const T& y) {
  if (x > y) x = y;
  return x;
}
template <class T>
T& smax(T& x, const T& y) {
  if (x < y) x = y;
  return x;
}
template <class T>
T sqr(const T& x) {
  return x * x;
}
template <class T>
T gcd(T a, T b) {
  for (a = abs(a), b = abs(b); a && b; a >= b ? a %= b : b %= a)
    ;
  return a + b;
}
template <typename Iterator>
void print(const char* format, Iterator first, Iterator last,
           const char* delimiter = " ", const char* closing = "\n") {
  for (; first != last; ++first != last ? printf("%s", delimiter) : 0)
    printf(format, *first);
  printf("%s", closing);
}
int x[4], y[4];
int xt[4], yt[4];
int ans, cur;
int xa[4], ya[4];
void update(bool rev) {
  if (ans != -1 && cur > ans) return;
  ans = cur;
  for (int i(0), b_(4); i < b_; ++i) {
    xa[i] = xt[i];
    ya[i] = yt[i];
    if (rev) swap(xa[i], ya[i]);
  }
}
void move(int i, int xx, int yy) {
  smax(cur, abs(x[i] - xx) + abs(y[i] - yy));
  xt[i] = xx;
  yt[i] = yy;
}
int main() {
  cin.tie(NULL);
  int t;
  for (scanf("%d", &t); t--;) {
    for (int i(0), b_(4); i < b_; ++i) scanf("%d%d", x + i, y + i);
    ans = -1;
    for (int m(0), b_(1 << 4); m < b_; ++m) {
      vector<pair<int, int>> fx, fy;
      for (int i(0), b_(4); i < b_; ++i) {
        if (m >> i & 1)
          fx.emplace_back(x[i], i);
        else
          fy.emplace_back(y[i], i);
      }
      bool rev = static_cast<int>((fy).size()) > static_cast<int>((fx).size());
      if (static_cast<int>((fy).size()) == static_cast<int>((fx).size())) {
        bool diffx = fx[0].first != fx[1].first;
        bool diffy = fy[0].first != fy[1].first;
        if (!diffy && !diffx) continue;
        if (diffy && !diffx) rev = true;
      }
      if (rev) {
        swap(fx, fy);
        for (int i(0), b_(4); i < b_; ++i) swap(x[i], y[i]);
      }
      sort((fx).begin(), (fx).end());
      switch (static_cast<int>((fx).size())) {
        case 4: {
          if (fx[0].first != fx[1].first || fx[1].first == fx[2].first ||
              fx[2].first != fx[3].first)
            break;
          if (y[fx[0].second] > y[fx[1].second]) swap(fx[0], fx[1]);
          if (y[fx[2].second] > y[fx[3].second]) swap(fx[2], fx[3]);
          int l = fx[2].first - fx[1].first;
          auto calc = [&](int yy) -> int {
            int res = 0;
            for (int i(0), b_(4); i < b_; ++i)
              smax(res, abs(y[fx[i].second] - ((i & 1) ? yy + l : yy)));
            return res;
          };
          int yl = -INF, yr = INF;
          while (yl + 1 < yr) {
            int ym = (yl + yr) / 2 - 1;
            int cym = calc(ym), cym1 = calc(ym + 1);
            if (cym == cym1) {
              yl = ym;
              break;
            }
            if (cym < cym1)
              yr = ym + 1;
            else
              yl = ym + 1;
          }
          for (int i(0), b_(4); i < b_; ++i) {
            xt[fx[i].second] = fx[i].first;
            yt[fx[i].second] = (i & 1) ? yl + l : yl;
          }
          cur = calc(yl);
          update(rev);
          break;
        }
        case 3: {
          if (fx[0].first == fx[1].first) {
            if (fx[1].first == fx[2].first) break;
          } else {
            if (fx[1].first == fx[2].first)
              swap(fx[0], fx[2]);
            else
              break;
          }
          if (y[fx[0].second] > y[fx[1].second]) swap(fx[0], fx[1]);
          int x0 = fx[0].first, x2 = fx[2].first;
          int y0 = fy[0].first;
          int l = abs(x2 - x0);
          for (int y2 = y0 - l; y2 <= y0 + l; y2 += 2 * l) {
            cur = 0;
            move(fx[0].second, x0, min(y0, y2));
            move(fx[1].second, x0, max(y0, y2));
            move(fx[2].second, x2, y2);
            move(fy[0].second, x2, y0);
            update(rev);
          }
          break;
        }
        case 2: {
          if (fy[0].first == fy[1].first) {
            if (x[fy[0].second] > x[fy[1].second]) swap(fy[0], fy[1]);
            int x0 = fx[0].first, x1 = fx[1].first;
            int l = abs(x1 - x0);
            int y0 = fy[0].first;
            for (int y1 = y0 - l; y1 <= y0 + l; y1 += 2 * l) {
              cur = 0;
              move(fx[0].second, x0, y1);
              move(fx[1].second, x1, y1);
              move(fy[0].second, min(x0, x1), y0);
              move(fy[1].second, max(x0, x1), y0);
              update(rev);
            }
          } else {
            int x0 = fx[0].first, x1 = fx[1].first;
            int y0 = fy[0].first, y1 = fy[1].first;
            if (abs(x0 - x1) != abs(y0 - y1)) break;
            cur = 0;
            move(fx[0].second, x0, y0);
            move(fx[1].second, x1, y1);
            move(fy[0].second, x1, y0);
            move(fy[1].second, x0, y1);
            update(rev);
            cur = 0;
            move(fx[0].second, x0, y1);
            move(fx[1].second, x1, y0);
            move(fy[0].second, x0, y0);
            move(fy[1].second, x1, y1);
            update(rev);
          }
          break;
        }
      }
      if (rev) {
        for (int i(0), b_(4); i < b_; ++i) swap(x[i], y[i]);
      }
    }
    printf("%d\n", ans);
    if (ans != -1)
      for (int i(0), b_(4); i < b_; ++i) printf("%d %d\n", xa[i], ya[i]);
  }
  return 0;
}
