/*
看到这题首先想起来模拟
but。。。超时。。。
然后想起来打表查找
最先是把所有秒数都存起来
开了一个86400的数组然后把可以被3整除的赋值为1
其余为0
然后只需要查找区间中1的个数即可
结果。。。TLE。。。
后来看题解发现自己原来做了那么多的无用功
先是写了一个test()查出一共有28800个满足题意的钟表数
然后写入数据的时候就抛弃不符合的数
完成提交
AC
*/
#define LOCAL
#include<iostream>
#define N 28800
using namespace std;
int t[N];
int main()
{
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int count=0,h,m,s,n,i,start,end;
string a,b;
for(h=0;h<24;h++) //打表
{
for(m=0;m<60;m++)
{
for(s=0;s<60;s++)
{
if((h/10+h%10+m/10+m%10+s/10+s%10)%3==0)
t[count++]=h*10000+m*100+s;
}
}
}
while(cin>>n) //主体部分
{
while(n--)
{
cin>>a>>b;
start=((a[0]-'0')*10+a[1]-'0')*10000+((a[3]-'0')*10+a[4]-'0')*100+(a[6]-'0')*10+a[7]-'0';
end=((b[0]-'0')*10+b[1]-'0')*10000+((b[3]-'0')*10+b[4]-'0')*100+(b[6]-'0')*10+b[7]-'0';
count=0;
if(start<end)
{
for(i=0;i<N;i++)
if(t[i]>=start&&t[i]<=end)
count++;
}
else
{
for(i=0;i<N;i++)
if(t[i]<start&&t[i]>end)
count++;
count=28800-count;
}
cout<<count<<endl;
}
}
return 0;
}