#include <bits/stdc++.h>   using namespace std;   const int dx[4] = {1, 0};   const int dy[4] = {0, 1};   pair<int, vector<vector<int> > > MoveBotsDirs(       const vector<vector<int> >& bots_dirs) {     map<int, int> xs;     map<int, int> ys;     for (int i = 0; i < bots_dirs.size(); ++i) {       if (bots_dirs[i][2] == 0) {         xs[bots_dirs[i][0]]++;       } else {         ys[bots_dirs[i][1]]++;       }     }     if (xs.size() > 2 || ys.size() > 2) {       return make_pair(-1, vector<vector<int> >());     }     for (map<int, int>::const_iterator it = xs.begin(); it != xs.end(); ++it) {       if (it->second > 2) {         return make_pair(-1, vector<vector<int> >());       }     }     for (map<int, int>::const_iterator it = ys.begin(); it != ys.end(); ++it) {       if (it->second > 2) {         return make_pair(-1, vector<vector<int> >());       }     }     if (xs.size() < 2 && ys.size() < 2) {       return make_pair(-1, vector<vector<int> >());     }     if (ys.size() < 2) {       vector<vector<int> > bots_dirs2;       for (int i = 0; i < bots_dirs.size(); ++i) {         vector<int> bot;         bot.push_back(bots_dirs[i][1]);         bot.push_back(bots_dirs[i][0]);         bot.push_back(bots_dirs[i][3]);         bot.push_back(bots_dirs[i][2]);         bots_dirs2.push_back(bot);       }       pair<int, vector<vector<int> > > sol = MoveBotsDirs(bots_dirs2);       for (int i = 0; i < sol.second.size(); ++i) {         swap(sol.second[i][0], sol.second[i][1]);       }       return sol;     }     int ymin = ys.begin()->first;     int ymax = ys.rbegin()->first;     int side = ymax - ymin;     set<int> xcand;     vector<int> Xs;     for (map<int, int>::const_iterator it = xs.begin(); it != xs.end(); ++it) {       xcand.insert(it->first);     }     for (int i = 0; i < bots_dirs.size(); ++i) {       xcand.insert(bots_dirs[i][0]);       xcand.insert(bots_dirs[i][0] - side);       for (int j = 0; j < bots_dirs.size(); ++j) {         xcand.insert((bots_dirs[i][0] + bots_dirs[j][0] - side) / 2);         xcand.insert((bots_dirs[i][0] + bots_dirs[j][0] - side) / 2 + 1);         xcand.insert((bots_dirs[i][0] + bots_dirs[j][0] - side) / 2 - 1);         xcand.insert((bots_dirs[i][0] + bots_dirs[j][0] - side) / 2 - side);         xcand.insert((bots_dirs[i][0] + bots_dirs[j][0] - side) / 2 + 1 - side);         xcand.insert((bots_dirs[i][0] + bots_dirs[j][0] - side) / 2 - 1 - side);         xcand.insert((bots_dirs[i][0] + bots_dirs[j][0]) / 2);         xcand.insert((bots_dirs[i][0] + bots_dirs[j][0]) / 2 + 1);         xcand.insert((bots_dirs[i][0] + bots_dirs[j][0]) / 2 - 1);         xcand.insert((bots_dirs[i][0] + bots_dirs[j][0]) / 2 - side);         xcand.insert((bots_dirs[i][0] + bots_dirs[j][0]) / 2 + 1 - side);         xcand.insert((bots_dirs[i][0] + bots_dirs[j][0]) / 2 - 1 - side);       }     }     pair<int, vector<vector<int> > > res;     res.first = -1;     for (set<int>::const_iterator it = xcand.begin(); it != xcand.end(); ++it) {       int xmin = *it;       int xmax = xmin + side;       vector<vector<int> > nodes(4);       nodes[0].push_back(xmin);       nodes[0].push_back(ymin);       nodes[1].push_back(xmin);       nodes[1].push_back(ymax);       nodes[2].push_back(xmax);       nodes[2].push_back(ymax);       nodes[3].push_back(xmax);       nodes[3].push_back(ymin);       vector<int> perm;       for (int i = 0; i < 4; ++i) {         perm.push_back(i);       }       do {         vector<vector<int> > new_pos;         for (int i = 0; i < 4; ++i) {           new_pos.push_back(nodes[perm[i]]);         }         bool can_go = true;         int max_steps = 0;         for (int i = 0; i < 4; ++i) {           if (bots_dirs[i][2] == 0) {             if (new_pos[i][0] != bots_dirs[i][0]) {               can_go = false;               break;             }             int steps = abs((new_pos[i][1] - bots_dirs[i][1]) / bots_dirs[i][3]);             max_steps = max(max_steps, steps);           } else {             if (new_pos[i][1] != bots_dirs[i][1]) {               can_go = false;               break;             }             int steps = abs((new_pos[i][0] - bots_dirs[i][0]) / bots_dirs[i][2]);             max_steps = max(max_steps, steps);           }         }         if (can_go) {           if (res.first == -1) {             res.first = max_steps;             res.second = new_pos;           } else if (max_steps < res.first) {             res.first = max_steps;             res.second = new_pos;           }         }       } while (next_permutation(perm.begin(), perm.end()));     }     return res;   }   pair<int, vector<vector<int> > > MoveBots(const vector<vector<int> >& bots) {     pair<int, vector<vector<int> > > res;     res.first = -1;     int dir[4];     for (dir[0] = 0; dir[0] < 2; ++dir[0]) {       for (dir[1] = 0; dir[1] < 2; ++dir[1]) {         for (dir[2] = 0; dir[2] < 2; ++dir[2]) {           for (dir[3] = 0; dir[3] < 2; ++dir[3]) {             vector<vector<int> > bots_dirs;             for (int i = 0; i < 4; ++i) {               bots_dirs.push_back(bots[i]);               bots_dirs[i].push_back(dx[dir[i]]);               bots_dirs[i].push_back(dy[dir[i]]);             }             pair<int, vector<vector<int> > > curres = MoveBotsDirs(bots_dirs);             if (res.first == -1 && curres.first != -1) {               res = curres;             } else if (curres.first != -1 && curres.first < res.first) {               res = curres;             }           }         }       }     }     return res;   }   pair<int, vector<vector<int> > > MoveBotsSlow(       const vector<vector<int> >& bots) {     const int CHECK = 10;     pair<int, vector<vector<int> > > res;     res.first = -1;     for (int x = -CHECK; x <= CHECK; ++x) {       for (int y = -CHECK; y <= CHECK; ++y) {         for (int side = 1; side <= CHECK; ++side) {           int xmin = x;           int ymin = y;           int xmax = x + side;           int ymax = y + side;           vector<vector<int> > pos(4);           pos[0].push_back(xmin);           pos[0].push_back(ymin);           pos[1].push_back(xmin);           pos[1].push_back(ymax);           pos[2].push_back(xmax);           pos[2].push_back(ymax);           pos[3].push_back(xmax);           pos[3].push_back(ymin);           vector<int> perm;           for (int i = 0; i < 4; ++i) {             perm.push_back(i);           }           do {             vector<vector<int> > new_pos;             for (int i = 0; i < 4; ++i) {               new_pos.push_back(pos[perm[i]]);             }             int max_steps = 0;             bool can_go = true;             for (int i = 0; i < 4; ++i) {               if (new_pos[i][0] == bots[i][0]) {                 max_steps = max(max_steps, abs(new_pos[i][1] - bots[i][1]));               } else if (new_pos[i][1] == bots[i][1]) {                 max_steps = max(max_steps, abs(new_pos[i][0] - bots[i][0]));               } else {                 can_go = false;               }             }             if (can_go) {               if (res.first == -1) {                 res.first = max_steps;                 res.second = new_pos;               } else if (max_steps < res.first) {                 res.first = max_steps;                 res.second = new_pos;               }             }           } while (next_permutation(perm.begin(), perm.end()));         }       }     }     return res;   }   int main() {     int tests;     cin >> tests;     for (int test_index = 0; test_index < tests; ++test_index) {       vector<vector<int> > bots(4, vector<int>(2));       for (int i = 0; i < 4; ++i) {         for (int j = 0; j < 2; ++j) {           scanf( %d , &bots[i][j]);         }       }       pair<int, vector<vector<int> > > new_pos = MoveBots(bots);       if (new_pos.first == -1) {         printf( -1 n );         continue;       } else {         printf( %d n , new_pos.first);         for (int i = 0; i < 4; ++i) {           printf( %d %d n , new_pos.second[i][0], new_pos.second[i][1]);         }       }     }     return 0;   }