#define E 0.00000001
main(n,a,b,c,d,p,q,r,D){
	for(scanf("%d",&n);n;n--){
		scanf("%d%d%d%d",&a,&b,&c,&d); //fx=ax3+bx2+cx+d
		p=3*a,q=2*b,r=c,D=q*q-4*p*r; //f'x=3ax2+2bx+c D: f'x=0?
		if(D>0){
			double x1=(-b-sqrt(D))/(double)p,x2=(-b+sqrt(D))/(double)p;
			double y1=a*x1*x1*x1+b*x1*x1+c*x1+d;
			double y2=a*x2*x2*x2+b*x2*x2+c*x2+d;
//printf("---%f %f %f %f\n",x1,x2,y1,y2);
			if(fabs(y1)>E&&fabs(y2)>E&&y1*y2>0)goto one;
			if(x1>=0)
				puts(x1==0?"2 0":"3 0");
			else if(x2<=0)
				puts(x2==0?"0 2":"0 3");
			else{
				if(a>0)
					puts(d>0?"1 2":d<0?"2 1":"1 1");
				else
					puts(d<0?"1 2":d>0?"2 1":"1 1");
			}
		}else{
one:
			if(D==0){
				if(a>0)
					puts(d>0?"0 3":d<0?"3 0":"0 0");
				else
					puts(d<0?"0 3":d>0?"3 0":"0 0");
			}else{
				if(a>0)
					puts(d>0?"0 1":d<0?"1 0":"0 0");
				else
					puts(d<0?"0 1":d>0?"1 0":"0 0");
			}
		}
	}
	return 0;
}