#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
const int oo = 0x3f3f3f3f;
int a[4][2];
int ans;
int goal[4][2];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    ans = oo;
    for (int i = (0), _end_ = (4); i < _end_; ++i)
      scanf("%d%d", a[i], a[i] + 1);
    for (int rev = (0), _end_ = (2); rev < _end_; ++rev) {
      for (int i = (0), _end_ = (4); i < _end_; ++i)
        for (int j = (0), _end_ = (4); j < _end_; ++j)
          if (a[i][0] < a[j][0]) {
            int len = a[j][0] - a[i][0];
            vector<int> res;
            for (int k = (0), _end_ = (4); k < _end_; ++k)
              if (k != i && k != j) res.push_back(k);
            if (a[res[0]][0] != a[i][0]) swap(res[0], res[1]);
            if (a[res[0]][0] == a[i][0] && a[res[1]][0] == a[j][0]) {
              int foo[4] = {a[i][1], a[res[0]][1] - len, a[j][1],
                            a[res[1]][1] - len};
              int mid =
                  (*min_element(foo, foo + 4) + *max_element(foo, foo + 4)) >>
                  1;
              int Max = 0;
              for (int i = (0), _end_ = (4); i < _end_; ++i)
                chkmax(Max, abs(mid - foo[i]));
              if (chkmin(ans, Max)) {
                for (int i = (0), _end_ = (4); i < _end_; ++i)
                  goal[i][0] = a[i][0];
                goal[i][1] = mid;
                goal[res[0]][1] = mid + len;
                goal[j][1] = mid;
                goal[res[1]][1] = mid + len;
                if (rev)
                  for (int ii = (0), _end_ = (4); ii < _end_; ++ii)
                    swap(goal[ii][0], goal[ii][1]);
              }
            }
            for (int k = (0), _end_ = (4); k < _end_; ++k)
              for (int l = (0), _end_ = (2); l < _end_; ++l) {
                int coo[4][2] = {{a[i][0], a[k][1]},
                                 {a[j][0], a[k][1] + (l ? len : -len)}};
                int pos[4] = {0, 1, 2, 3};
                do {
                  bool failed = 0;
                  int Max = 0;
                  for (int i = (0), _end_ = (4); i < _end_; ++i) {
                    int gx = coo[i & 1][0], gy = coo[i >> 1][1];
                    int ox = a[pos[i]][0], oy = a[pos[i]][1];
                    if (ox != gx && oy != gy) {
                      failed = 1;
                      break;
                    } else if (ox != gx)
                      chkmax(Max, abs(ox - gx));
                    else if (oy != gy)
                      chkmax(Max, abs(oy - gy));
                  }
                  if (!failed && chkmin(ans, Max))
                    for (int ii = (0), _end_ = (4); ii < _end_; ++ii)
                      for (int jj = (0), _end_ = (2); jj < _end_; ++jj)
                        goal[pos[ii]][jj] = coo[ii >> (jj ^ rev) & 1][jj ^ rev];
                } while (next_permutation(pos, pos + 4));
              }
          }
      for (int i = (0), _end_ = (4); i < _end_; ++i) swap(a[i][0], a[i][1]);
    }
    if (ans == oo)
      printf("-1\n");
    else {
      printf("%d\n", ans);
      for (int i = (0), _end_ = (4); i < _end_; ++i)
        printf("%d %d\n", goal[i][0], goal[i][1]);
    }
  }
  return 0;
}
