//2840#includestdio.hmain(){int t,a,b;scanf("%d",t);while(t--){scanf("%d:%d",a,b);b?puts("0"):printf("%d\n",a12?a-12:a+12);}}
//2840
#include<stdio.h>
main()
{
int t,a,b;
scanf("%d",&t);
while(t--)
{
scanf("%d:%d",&a,&b);
b?puts("0"):printf("%d\n",a>12?a-12:a+12);
}
}