#define E 0.00000001
#define zero(n) (fabs(n)<E)
main(n,a,b,c,d,p,q,r,D,f){
	for(scanf("%d",&n);n;n--){
		scanf("%d%d%d%d",&a,&b,&c,&d); //fx=ax3+bx2+cx+d
		if(a<0)a=-a,b=-b,c=-c,d=-d;// won't lose generality
		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=(-q-sqrt(D))/p/2,x2=(-q+sqrt(D))/p/2;
			double y1=a*x1*x1*x1+b*x1*x1+c*x1+d;
			double y2=a*x2*x2*x2+b*x2*x2+c*x2+d;
			if(!zero(y1)&&!zero(y2)>E&&y1*y2>0)goto one;
			if(zero(x1)){
				if(d==0)k[0]=1,k[1]=0;
				else k[0]=2,k[1]=1;
			}else if(zero(x2)){
				if(d==0)k[0]=0,k[1]=1;
				else k[0]=1,k[1]=2;
			}else if(x1>0){
				if(d>0)k[0]=2,k[1]=1;
				else if(d<0)k[0]=3,k[1]=0;
				else k[0]=2,k[1]=0;
			}else if(x2<0){
				if(d>0)k[0]=0,k[1]=3;
				else if(d<0)k[0]=1,k[1]=2;
				else k[0]=0,k[1]=2;
			}else{
				if(d>0)k[0]=2,k[1]=1;
				else if(d<0)k[0]=1,k[1]=2;
				else k[0]=1,k[1]=1;
			}
		}else if(D==0){
			if(d>0)k[0]=0,k[1]=3;
			else if(d<0)k[0]=1,k[1]=0;
		}else{
one:
			if(d>0)k[0]=0,k[1]=1;
			else if(d<0)k[0]=1,k[1]=0;
		}
		printf("%d %d\n",k[0],k[1]);
	}
	return 0;
}