#include <bits/stdc++.h>
using namespace std;
int ans1;
pair<int, int> a[5], ans2[5];
int per[5], st1[5], st2[5];
inline int max(int a, int b, int c, int d) { return max(max(a, b), max(c, d)); }
inline int min(int a, int b, int c, int d) { return min(min(a, b), min(c, d)); }
pair<int, int> calc(int a, int b, int c, int d, int len) {
  int l = 0, r = 5e8;
  while (l < r) {
    int m = ((l + r) >> 1);
    if (max(a - m, b - m, c - m - len, d - m - len) <=
            min(a + m, b + m, c + m - len, d + m - len) ||
        max(a - m, b - m, c - m + len, d - m + len) <=
            min(a + m, b + m, c + m + len, d + m + len))
      r = m;
    else
      l = m + 1;
  }
  if (max(a - l, b - l, c - l - len, d - l - len) <=
      min(a + l, b + l, c + l - len, d + l - len)) {
    int t = max(a - l, b - l, c - l - len, d - l - len);
    return pair<int, int>(t, t + len);
  } else {
    int t = max(a - l, b - l, c - l + len, d - l + len);
    return pair<int, int>(t, t - len);
  }
}
void check() {
  pair<int, int> cur[5];
  for (int i = 1; i < 5; i++) cur[i] = a[per[i]];
  int x1, x2, yy, y2;
  bool v1 = 0, v2 = 0, v3 = 0, v4 = 0;
  if (!st1[1] && !st1[2]) {
    if (cur[1].first != cur[2].first) return;
    x1 = cur[1].first;
  } else if (!st1[1])
    x1 = cur[1].first;
  else if (!st1[2])
    x1 = cur[2].first;
  else
    v1 = 1;
  if (!st1[3] && !st1[4]) {
    if (cur[3].first != cur[4].first) return;
    x2 = cur[3].first;
  } else if (!st1[3])
    x2 = cur[3].first;
  else if (!st1[4])
    x2 = cur[4].first;
  else
    v2 = 1;
  if (st1[1] && st1[3]) {
    if (cur[1].second != cur[3].second) return;
    yy = cur[1].second;
  } else if (st1[1])
    yy = cur[1].second;
  else if (st1[3])
    yy = cur[3].second;
  else
    v3 = 1;
  if (st1[2] && st1[4]) {
    if (cur[2].second != cur[4].second) return;
    y2 = cur[2].second;
  } else if (st1[2])
    y2 = cur[2].second;
  else if (st1[4])
    y2 = cur[4].second;
  else
    v4 = 1;
  if (!v1 && !v2 && x1 == x2) return;
  if (!v3 && !v4 && yy == y2) return;
  if (!v1 && !v2 && !v3 && !v4 && abs(x1 - x2) != abs(yy - y2)) return;
  if (v1 && v2) {
    pair<int, int> t = calc(cur[1].first, cur[2].first, cur[3].first,
                            cur[4].first, abs(yy - y2));
    x1 = t.first;
    x2 = t.second;
  } else if (v3 && v4) {
    pair<int, int> t = calc(cur[1].second, cur[3].second, cur[2].second,
                            cur[4].second, abs(x1 - x2));
    yy = t.first;
    y2 = t.second;
  } else if (v1)
    x1 = x2 + ((st2[1]) ? 1 : -1) * abs(yy - y2);
  else if (v2)
    x2 = x1 + ((st2[2]) ? 1 : -1) * abs(yy - y2);
  else if (v3)
    yy = y2 + ((st2[3]) ? 1 : -1) * abs(x1 - x2);
  else if (v4)
    y2 = yy + ((st2[4]) ? 1 : -1) * abs(x1 - x2);
  int len = 0;
  len = max(len, (st1[1]) ? abs(cur[1].first - x1) : abs(cur[1].second - yy));
  len = max(len, (st1[2]) ? abs(cur[2].first - x1) : abs(cur[2].second - y2));
  len = max(len, (st1[3]) ? abs(cur[3].first - x2) : abs(cur[3].second - yy));
  len = max(len, (st1[4]) ? abs(cur[4].first - x2) : abs(cur[4].second - y2));
  if (len < ans1) {
    ans1 = len;
    ans2[per[1]] = pair<int, int>(x1, yy);
    ans2[per[2]] = pair<int, int>(x1, y2);
    ans2[per[3]] = pair<int, int>(x2, yy);
    ans2[per[4]] = pair<int, int>(x2, y2);
  }
}
void dfs(int d) {
  if (d > 4) {
    check();
    return;
  }
  for (st1[d] = 0; st1[d] < 2; st1[d]++)
    for (st2[d] = 0; st2[d] < 2; st2[d]++) dfs(d + 1);
}
int main() {
  int cases;
  scanf("%d", &cases);
  for (; cases; cases--) {
    ans1 = 0x3f3f3f3f;
    for (int i = 1; i < 5; i++) scanf("%d%d", &a[i].first, &a[i].second);
    for (int i = 1; i < 5; i++) per[i] = i;
    do {
      dfs(1);
    } while (next_permutation(per + 1, per + 5));
    if (ans1 < 0x3f3f3f3f) {
      printf("%d\n", ans1);
      for (int i = 1; i < 5; i++)
        printf("%d %d\n", ans2[i].first, ans2[i].second);
    } else
      puts("-1");
  }
  return 0;
}
