#include<stdio.h>
#include<math.h>
struct Point {
  double x;
  double y;
};
int main(void) {
  int i, q;
  double dt1, dt2, t;
  struct Point base, hypo, p[4];
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    int j;
    for (j = 0; j < 4; j++) scanf("%lf %lf", &p[j].x, &p[j].y);
    base.x = p[1].x - p[0].x;
    base.y = p[1].y - p[0].y;
    hypo.x = p[2].x - p[0].x;
    hypo.y = p[2].y - p[0].y;
    dt1 = fabs(base.x * hypo.y - base.y * hypo.x);
    hypo.x = p[3].x - p[0].x;
    hypo.y = p[3].y - p[0].y;
    dt2 = fabs(base.x * hypo.y - base.y * hypo.x);
    t = dt1 / (dt1 + dt2);
    hypo.x = p[2].x + t * (p[3].x - p[2].x);
    hypo.y = p[2].y + t * (p[3].y - p[2].y);
    printf("%f %f\n", hypo.x, hypo.y);
  }
}
