for i in range(int(input())):
s, x= [z for z in input().split()]
t= s[:2]
u= s[3:]
x= int(x)
t= int(t)
u= int(u)
v= t*60 + u
y= [0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412]
b= set()
for j in range(2880):
if v in y:
b.add(v)
v += x
v %= 1440
print(len(b))
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void seive(bool primes[], int n) {
for (int i = 1; i <= n; i++) {
primes[i] = 1;
}
primes[1] = 0;
primes[0] = 0;
int x = sqrt(n);
for (int i = 2; i <= x; i++) {
if (primes[i] == 1) {
for (int j = i * i; j <= n; j += i) {
primes[j] = 0;
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie();
int arr[16]={0,70,140,280,210,350,601,671,741,811,881,951,1202,1272,1342,1412};
int t;
cin >> t;
while (t--){
string s;
int x;
cin >> s >> x;
int c=0;
c+=(int)(s[0]-48)*60*10;
c+=(int)(s[1]-48)*60;
c+=(int)(s[3]-48)*10;
c+=(int)(s[4]-48);
map<int ,int>m;
// cout << c<<endl;
int cnt = 0;
int e=0;
// cout << c;
int y = 10000;
while(y--)
{
// e+=x;
for (int i = 0; i < 16; ++i) {
if(c==arr[i] && m[arr[i]]!=5){
cnt++;
m[arr[i]]=5;
}
}
c+=x;
c=(c%1440);
}
cout << cnt<<endl;
}
}
1133C - Balanced Team | 1704A - Two 0-1 Sequences |
1467A - Wizard of Orz | 1714E - Add Modulo 10 |
1714A - Everyone Loves to Sleep | 764A - Taymyr is calling you |
1714B - Remove Prefix | 1264F - Beautiful Fibonacci Problem |
52A - 123-sequence | 1543A - Exciting Bets |
1714D - Color with Occurrences | 215B - Olympic Medal |
1445A - Array Rearrangment | 1351A - A+B (Trial Problem) |
935B - Fafa and the Gates | 1291A - Even But Not Even |
1269A - Equation | 441A - Valera and Antique Items |
1702C - Train and Queries | 816B - Karen and Coffee |
838D - Airplane Arrangements | 148B - Escape |
847G - University Classes | 1110A - Parity |
1215B - The Number of Products | 604C - Alternative Thinking |
1204C - Anna Svyatoslav and Maps | 322A - Ciel and Dancing |
1689B - Mystic Permutation | 1711B - Party |