#include <iostream>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long ll;
const double EPS=1e-8;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout<<fixed<<setprecision(10);
int q;
cin>>q;
while(q--){
int op;
cin>>op;
ll x1,x2,x3,y1,y2,y3;
cin>>x1>>y1>>x2>>y2>>x3>>y3;
ll dx=x2-x1;
ll dy=y2-y1;
ll cx=x3-x1;
ll cy=y3-y1;
ll dot=cx*dx+cy*dy;
ll lensq=dx*dx+dy*dy;
double t=(double)dot/lensq;
if(op==1||op==2){
double px=x1+t*dx;
double py=y1+t*dy;
if(op==1){
cout<<px<<" "<<py<<endl;
}
else {
ll cross=abs(dx*cy-dy*cx);
double dis=(double)cross/sqrt(lensq);
cout<<dis<<endl;
}
}
else{
if(t<0)t=0;
if(t>1)t=1;
double px=x1+t*dx;
double py=y1+t*dy;
if(op==3){
cout<<px<<" "<<py<<endl;
}
else{
double dcx=px-x3;
double dcy=py-y3;
double dis=sqrt(dcx*dcx+dcy*dcy);
cout<<dis<<endl;
}
}
}
return 0;
}