#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int x[4], y[4];
int tx[4], ty[4];
int ansx[4], ansy[4];
int curans;
int p[4];
void check() {
  int res = 0;
  for (int i = 0; i < 4; i++)
    if (tx[p[i]] == x[i])
      res = max(res, abs(ty[p[i]] - y[i]));
    else if (ty[p[i]] == y[i])
      res = max(res, abs(tx[p[i]] - x[i]));
    else
      res = INF;
  if (res < curans) {
    curans = res;
    for (int i = 0; i < 4; i++) ansx[i] = tx[p[i]], ansy[i] = ty[p[i]];
  }
  return;
}
bool vis[4];
void dfs(int now) {
  if (now == 4) {
    check();
    return;
  }
  for (p[now] = 0; p[now] < 4; p[now]++)
    if (!vis[p[now]]) {
      vis[p[now]] = true;
      dfs(now + 1);
      vis[p[now]] = false;
    }
  return;
}
int X[4], Y[4];
void update(int s) {
  int numx = 0, numy = 0;
  for (int i = 0; i < 4; i++)
    if (s & (1 << i))
      X[numx++] = x[i];
    else
      Y[numy++] = y[i];
  if (!numx || !numy) return;
  if (numx == 2) {
    if (X[0] > X[1]) swap(X[0], X[1]);
    if (Y[0] > Y[1]) swap(Y[0], Y[1]);
    if (X[1] - X[0] == Y[1] - Y[0]) {
      tx[0] = X[0], ty[0] = Y[0];
      tx[1] = X[0], ty[1] = Y[1];
      tx[2] = X[1], ty[2] = Y[0];
      tx[3] = X[1], ty[3] = Y[1];
      dfs(0);
    }
    if (X[0] == X[1]) {
      int d = Y[1] - Y[0];
      tx[0] = X[0], ty[0] = Y[0];
      tx[1] = X[0] + d, ty[1] = Y[0];
      tx[2] = X[0], ty[2] = Y[1];
      tx[3] = X[0] + d, ty[3] = Y[1];
      dfs(0);
      tx[0] = X[0], ty[0] = Y[0];
      tx[1] = X[0] - d, ty[1] = Y[0];
      tx[2] = X[0], ty[2] = Y[1];
      tx[3] = X[0] - d, ty[3] = Y[1];
      dfs(0);
    }
    if (Y[0] == Y[1]) {
      int d = X[1] - X[0];
      tx[0] = X[0], ty[0] = Y[0];
      tx[1] = X[0], ty[1] = Y[0] + d;
      tx[2] = X[1], ty[2] = Y[0];
      tx[3] = X[1], ty[3] = Y[0] + d;
      dfs(0);
      tx[0] = X[0], ty[0] = Y[0];
      tx[1] = X[0], ty[1] = Y[0] - d;
      tx[2] = X[1], ty[2] = Y[0];
      tx[3] = X[1], ty[3] = Y[0] - d;
      dfs(0);
    }
  } else if (numx == 1) {
    int mn = INF, mx = -INF;
    for (int i = 0; i < numy; i++) mn = min(mn, Y[i]), mx = max(mx, Y[i]);
    int d = mx - mn;
    tx[0] = X[0], ty[0] = mn;
    tx[1] = X[0] + d, ty[1] = mn;
    tx[2] = X[0], ty[2] = mx;
    tx[3] = X[0] + d, ty[3] = mx;
    dfs(0);
    tx[0] = X[0], ty[0] = mn;
    tx[1] = X[0] - d, ty[1] = mn;
    tx[2] = X[0], ty[2] = mx;
    tx[3] = X[0] - d, ty[3] = mx;
    dfs(0);
  } else {
    int mn = INF, mx = -INF;
    for (int i = 0; i < numx; i++) mn = min(mn, X[i]), mx = max(mx, X[i]);
    int d = mx - mn;
    tx[0] = mn, ty[0] = Y[0];
    tx[1] = mn, ty[1] = Y[0] + d;
    tx[2] = mx, ty[2] = Y[0];
    tx[3] = mx, ty[3] = Y[0] + d;
    dfs(0);
    tx[0] = mn, ty[0] = Y[0];
    tx[1] = mn, ty[1] = Y[0] - d;
    tx[2] = mx, ty[2] = Y[0];
    tx[3] = mx, ty[3] = Y[0] - d;
    dfs(0);
  }
  return;
}
void update2(int s) {
  int num1 = 0, num2 = 0;
  int mn = INF, mx = -INF;
  for (int i = 0; i < 4; i++) {
    mn = min(mn, x[i]);
    mx = max(mx, x[i]);
  }
  for (int i = 0; i < 4; i++)
    if (s & (1 << i)) {
      if (mn == x[i]) X[num1++] = y[i];
    } else {
      if (mx == x[i]) Y[num2++] = y[i];
    }
  if (num1 == 2 && num2 == 2) {
    int d = mx - mn;
    if (X[0] > X[1]) swap(X[0], X[1]);
    if (Y[0] > Y[1]) swap(Y[0], Y[1]);
    X[1] -= d;
    Y[1] -= d;
    X[2] = Y[0];
    X[3] = Y[1];
    int MN = INF, MX = -INF;
    for (int i = 0; i < 4; i++) {
      MN = min(MN, X[i]);
      MX = max(MX, X[i]);
    }
    int to = (MX + MN) / 2;
    tx[0] = mn, ty[0] = to;
    tx[1] = mn, ty[1] = to + d;
    tx[2] = mx, ty[2] = to;
    tx[3] = mx, ty[3] = to + d;
    dfs(0);
  }
  num1 = 0, num2 = 0;
  mn = INF, mx = -INF;
  for (int i = 0; i < 4; i++) {
    mn = min(mn, y[i]);
    mx = max(mx, y[i]);
  }
  for (int i = 0; i < 4; i++)
    if (s & (1 << i)) {
      if (mn == y[i]) X[num1++] = x[i];
    } else {
      if (mx == y[i]) Y[num2++] = x[i];
    }
  if (num1 == 2 && num2 == 2) {
    int d = mx - mn;
    if (X[0] > X[1]) swap(X[0], X[1]);
    if (Y[0] > Y[1]) swap(Y[0], Y[1]);
    X[1] -= d;
    Y[1] -= d;
    X[2] = Y[0];
    X[3] = Y[1];
    int MN = INF, MX = -INF;
    for (int i = 0; i < 4; i++) {
      MN = min(MN, X[i]);
      MX = max(MX, X[i]);
    }
    int to = (MX + MN) / 2;
    ty[0] = mn, tx[0] = to;
    ty[1] = mn, tx[1] = to + d;
    ty[2] = mx, tx[2] = to;
    ty[3] = mx, tx[3] = to + d;
    dfs(0);
  }
  return;
}
void solve() {
  for (int i = 0; i < 4; i++) scanf("%d %d", &x[i], &y[i]);
  curans = INF;
  for (int s = 0; s < 16; s++) {
    update(s);
    update2(s);
  }
  if (curans == INF)
    printf("-1\n");
  else {
    printf("%d\n", curans);
    for (int i = 0; i < 4; i++) printf("%d %d\n", ansx[i], ansy[i]);
  }
  return;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
  return 0;
}
