#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const int inf = 1000000009;
int i, j, k, m, n, l;
int ans;
bool upd(bool& fx, int& x, int y) {
  if (!fx) {
    x = y;
    fx = true;
    return true;
  }
  return x == y;
}
void solve2(int d, int a1, int a2, int b1, int b2, int& c1, int& c2) {
  int P = 0, Q = 500000000, R;
  vector<int> z;
  z.push_back(a1);
  z.push_back(a2 - d);
  z.push_back(b1);
  z.push_back(b2 - d);
  sort(z.begin(), z.end());
  c1 = (z[0] + z.back()) / 2;
  c2 = c1 + d;
}
int best;
vector<pair<int, int> > solution;
void solve(const vector<pair<int, int> >& w) {
  vector<pair<int, int> > v = w;
  sort(v.begin(), v.end());
  best = -1;
  do {
    vector<int> index(4);
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++)
        if (v[i] == w[j]) index[i] = j;
    }
    for (int mask = 0; mask < 16; mask++) {
      bool good = true;
      int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
      bool fx1 = false, fx2 = false, fy1 = false, fy2 = false;
      for (int i = 0; i < 4; i++)
        if (mask & (1 << i)) {
          if (i == 0 || i == 2)
            good &= upd(fy1, y1, v[i].second);
          else
            good &= upd(fy2, y2, v[i].second);
        } else {
          if (i == 0 || i == 1)
            good &= upd(fx1, x1, v[i].first);
          else
            good &= upd(fx2, x2, v[i].first);
        }
      if (!good) continue;
      if (fx1 && fx2 && x1 >= x2) continue;
      if (fy1 && fy2 && y1 >= y2) continue;
      if (fx1 && fx2 && fy1 && fy2 && x2 - x1 != y2 - y1) continue;
      if (fx1 && fx2 && fy1 && !fy2)
        upd(fy2, y2, x2 - x1 + y1);
      else if (fx1 && fx2 && !fy1 && fy2)
        upd(fy1, y1, x1 - x2 + y2);
      else if (fx1 && !fx2 && fy1 && fy2)
        upd(fx2, x2, y2 - y1 + x1);
      else if (!fx1 && fx2 && fy1 && fy2)
        upd(fx1, x1, y1 - y2 + x2);
      if (fx1 && fx2 && fy1 && fy2) {
      } else if (fx1 && fx2) {
        solve2(x2 - x1, v[0].second, v[1].second, v[2].second, v[3].second, y1,
               y2);
      } else if (fy1 && fy2) {
        solve2(y2 - y1, v[0].first, v[2].first, v[1].first, v[3].first, x1, x2);
      } else {
        throw 12;
      }
      int mx = 0;
      mx = max(mx, abs(v[0].first - x1) + abs(v[0].second - y1));
      mx = max(mx, abs(v[1].first - x1) + abs(v[1].second - y2));
      mx = max(mx, abs(v[2].first - x2) + abs(v[2].second - y1));
      mx = max(mx, abs(v[3].first - x2) + abs(v[3].second - y2));
      if (best == -1 || mx < best) {
        best = mx;
        solution.resize(4);
        solution[index[0]] = pair<int, int>(x1, y1);
        solution[index[1]] = pair<int, int>(x1, y2);
        solution[index[2]] = pair<int, int>(x2, y1);
        solution[index[3]] = pair<int, int>(x2, y2);
      }
    }
    next_permutation(index.begin(), index.end());
  } while (next_permutation(v.begin(), v.end()));
}
int main() {
  cin >> n;
  while (n--) {
    vector<pair<int, int> > v;
    int x, y;
    for (int i = 0; i < 4; i++) {
      cin >> x >> y;
      v.push_back(pair<int, int>(x, y));
    }
    solve(v);
    if (best == -1) {
      cout << -1 << endl;
    } else {
      cout << best << endl;
      for (int i = 0; i < 4; i++)
        cout << solution[i].first << " " << solution[i].second << endl;
    }
  }
  return 0;
}
