// Arup Guha
// 8/25/2026
// Solution to 2026 UCF Locals Problem: Diamond Cutting

/***

    Let our quadrilaterial be points A, B, C and D read in that order.
    I will treat A as the "bottom" point and C as the "top" point, though
    those descriptions may not actually be accurate, also it's easier to see
    what I am describing if I rotate C to be vertically above A (this transformation
    doesn't fundamentally change anything. I won't physically do these transformations
    but it's just easier to "see" why our technique works if you visualize it like this.

                C

                            B
    D
                A

    Let lambda represents the ratio of the total journey from the starting point to the ending point
    made on the segment AB.

    If we go lambda of the way from from A to B (call this point E) and
    lambda of the way from C to B (call this point F), it should be fairly clear
    that the line segment formed by those two new points (EF) is vertical, just like AC. (More
    generally, no matter what our picture looks like, this line segment is guaranteed, via
    similar triangles, to be parallel to AC.) Do the same on the other side... to form GH:

                C
            H        F
                            B

    D                E
            G
                A

    Using the same argument, GH is parallel to AC. Although it doesn't look like it on my
    terrible ascii picture, it's guaranteed that EF and GH are the same length, also via
    similar triangles. (It's a proportionality argument. If I travel 1/3 of the way from
    C to B and A to B, then the new vertical line segment has to be 2/3 the length of AC.

    Now, the length of EG is lambda*BD. Similarly, the length of EF is AC(1-lambda), namely
    as lambda increases, EG increases linearly and AC EF decreases linearly. This gives us
    the equation

    lambda*BD = AC(1-lambda)

    Solve for lambda:

    lambda*BD = AC - AC*lambda
    lambda*BD + lambda*AC = AC
    lambda(AC + BD) = AC
    lambda = AC/(AC+BD)

    The solution below just converts this idea into code.

***/

using namespace std;

#include <bits/stdc++.h>

// A basic point class.
class pt {

    public:
        double x;
        double y;

        pt() {
            x = 0;
            y = 0;
        }

        pt(double myx, double myy) {
            x = myx;
            y = myy;
        }

        // Returns the vector from this point to e.
        pt getDirTo(pt e) {
            return pt(e.x-x, e.y-y);
        }

        // Returns the distance between this point and e.
        double distTo(pt e) {
            return sqrt( (e.x-x)*(e.x-x) + (e.y-y)*(e.y-y) );
        }
};

// Line segment class.
class lineseg {

    public:
        pt s;
        pt e;
        pt dir;

        // I set the start and end and the direction vector.
        lineseg(pt mys, pt mye) {
            s = mys;
            e = mye;
            dir = s.getDirTo(e);
        }

        // Returns the pt that is lambda from start to end. If lambda = 0, start is returned.
        // If lambda = 1, end is returned. lambda is in between 0 and 1 for this problem.
        pt getPtOnSeg(double lambda) {
            return pt(s.x+lambda*dir.x, s.y+lambda*dir.y);
        }
};

void solve(vector<pt>& quad);

int main() {

    // Process cases.
    int nC;
    cin >> nC;
    for (int loop=0; loop<nC; loop++) {

        vector<pt> quad;
        for (int i=0; i<4; i++) {
            pt tmp;
            cin >> tmp.x >> tmp.y;
            quad.push_back(tmp);
        }

        // Do it!
        solve(quad);
    }

    return 0;
}

// Solves one case.
void solve(vector<pt>& quad) {

    // These are the four relevant line segments.
    lineseg bottomRight(quad[0], quad[1]);
    lineseg bottomLeft(quad[0], quad[3]);
    lineseg topRight(quad[2], quad[1]);
    lineseg topLeft(quad[2], quad[3]);

    // My "up-down" diagonal length.
    double upDown = quad[0].distTo(quad[2]);

    // My other diagonal length.
    double leftRight = quad[1].distTo(quad[3]);

    // This is the ratio that we want to move on the bottomRight
    // segment to make all four sides the same length.
    double lambda = upDown/(leftRight+upDown);

    // Build answer in counter-clockwise order.
    vector<pt> res;
    res.push_back(bottomRight.getPtOnSeg(lambda));
    res.push_back(topRight.getPtOnSeg(lambda));
    res.push_back(topLeft.getPtOnSeg(lambda));
    res.push_back(bottomLeft.getPtOnSeg(lambda));

    // Ta da!
    for (int i=0; i<4; i++)
        cout << setprecision(12) << res[i].x << " " << res[i].y << "\n";
}
