#include<stdio.h>
int main(){
int t,a,b,ta,tb,T,t1,t2;
scanf("%d",&t);
while(t--){
int q,i,h;
q=0;
h=0;
scanf("%d %d",&a,&ta);
scanf("%d %d",&b,&tb);
scanf("%d:%d",&t1,&t2);
for(i=300;i<=1439;i+=b){
if(i+tb>t1*60+t2&&i<t1*60+t2+ta)
q+=1;
}
printf("%d\n",q+h);
}
return 0;
}