#include<stdio.h>
int main()
{
int t,n,m;
scanf("%d", &t);
while (t--)
{
int a, ta, b, tb, th, tm;
scanf("%d %d %d %d", &a, &ta, &b, &tb);
scanf("%d:%d", &th, &tm);
int ans = 0;
n = th * 60 + tm;
m = n + ta;
if (m > 23 * 60 + 59)
m = 23 * 60 + 59;
else
m--;
n -= tb;
if (n < 5 * 60)
n = 5 * 60;
else
n++;
if ((n - 5 * 60) % b == 0)
ans++;
ans += (m - 5 * 60) / b - (n - 5 * 60) / b;
printf("%d\n", ans);
}
return 0;
}