#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#include<map>
#include<vector>
#include<set>
#include<queue>
using namespace std;
int t, a, ta, b, tb, h, m;
int main()
{
scanf("%d", &t);
while (t--)
{
scanf("%d %d", &a, &ta);
scanf("%d %d", &b, &tb);
scanf("%d:%d", &h, &m);
int now = h * 60 + m;
int end = now + ta -1;
int maxx = 23 * 60 + 59;
int start = 5 * 60;
int ans = 0;
for (int i = start; i <= end&&i<=maxx; i += b)
{
if (i + tb > now&&i<=end&&i<=maxx)
{
ans++;
}
}
printf("%d\n", ans);
}
return 0;
}