Problem: For given two segments s1 and s2, print the coordinate of the cross point of them.

s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and p3.

Constraints

* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.
* The given segments have a cross point and are not in parallel.

Input

The entire input looks like:


q (the number of queries)
1st query
2nd query
...
qth query


Each query consists of integer coordinates of end points of s1 and s2 in the following format:


xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3


Output

For each query, print the coordinate of the cross point. The output values should be in a decimal fraction with an error less than 0.00000001.

Example

Input

3
0 0 2 0 1 1 1 -1
0 0 1 1 0 1 1 0
0 0 1 1 1 0 0 1


Output

1.0000000000 0.0000000000
0.5000000000 0.5000000000
0.5000000000 0.5000000000

Solution (in JAVA):

Solution:

import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());


		for(int i = 0; i < n; i++){
			String[] tmpArray = br.readLine().split(" ");

			Point2D[] points = new Point2D[4];

			for(int j = 0; j < 4; j++){
				int x = Integer.parseInt(tmpArray[j*2]);
				int y = Integer.parseInt(tmpArray[j*2 + 1]);

				points[j] = new Point2D.Double(x, y);
			}

			Line2D[] lines = new Line2D[2];
			for(int j = 0; j < 2; j++){
				lines[j] = new Line2D.Double(points[j*2], points[j*2 + 1]);
			}

			Point2D result = crossPoint(lines[0], lines[1]);

			System.out.printf("%.8f %.8f\n", result.getX(), result.getY());
		}
	}

	static Point2D crossPoint(Line2D l1, Line2D l2){
		if(!l1.intersectsLine(l2)){
			return null;
		}

		//l1がx軸に垂直
		if(l1.getX1() == l1.getX2()){
			double a = (l2.getY2() - l2.getY1())/(l2.getX2() - l2.getX1());

			return new Point2D.Double(l1.getX1(), a*(l1.getX1() - l2.getX1()) + l2.getY1());
		}
		//l2がx軸に垂直
		else if(l2.getX1() == l2.getX2()){
			double a = (l1.getY2() - l1.getY1())/(l1.getX2() - l1.getX1());

			return new Point2D.Double(l2.getX1(), a*(l2.getX1() - l1.getX1()) + l1.getY1());
		}
		else {
			double a1 = (l1.getY2() - l1.getY1())/(l1.getX2() - l1.getX1());
			double a2 = (l2.getY2() - l2.getY1())/(l2.getX2() - l2.getX1());
			double b1 = -a1*l1.getX1() + l1.getY1();
			double b2 = -a2*l2.getX1() + l2.getY1();

			double x = (b2 - b1)/(a1 - a2);
			double y = a1*x + b1;

			return new Point2D.Double(x, y);

		}

	}

}