#include<stdio.h>
int main()
{
int T;
scanf("%d",&T);
while (T--)
{
int a,at,b,bt;
scanf("%d %d",&a,&at);
scanf("%d %d",&b,&bt);
int x,y;
scanf("%d:%d",&x,&y);
int time;
time=x*60+y;
int end;
end=time+at;
int i,sum=0;
for (i=0;300+b*i<1440;i++)
{
if (300+b*i>time-bt&&300+b*i<end)
sum+=1;
}
printf("%d\n",sum);
}
}