#include <bits/stdc++.h>
using namespace std;
int a, Ta, b, Tb;
int h, m;
int main() {
int t;
cin >> t;
while (t--) {
scanf("%d %d", &a, &Ta);
scanf("%d %d", &b, &Tb);
scanf("%d:%d", &h, &m);
int Time = (h - 5) * 60 + m;
int ans = 0;
for (int i = 0; i < 1140; i += b) {
if (i < Time + Ta && i > Time - Tb) {
++ans;
}
}
printf("%d\n", ans);
}
return 0;
}