#include <stdio.h>
int main() {
int T,a,ta,b,tb;
int hh,mm,ms;
int m0,m1,ccj,xc,total;
m0=300;
scanf("%d",&T);
while(T--)
{
total=0;
scanf("%d %d",&a,&ta);
scanf("%d %d",&b,&tb);
scanf("%d:%d",&hh,&mm);
m1=hh*60+mm;
for(xc=300;xc<1440;xc+=b)
{
if(xc>m1-tb&&xc<m1+ta)
{
total+=1;
}
}
printf("%d\n",total);
}
return 0;
}