#include<stdio.h>
#include<stdlib.h>
int main()
{
int T;
scanf("%d",&T);
while(T--!=0)
{
int H,M;
scanf("%d:%d",&H,&M);
if(M!=0)
printf("0\n");
else{
if(H+12>24)
printf("%d\n",H-12);
else
printf("%d\n",H+12);
}
}
system("pause");
}
#include<stdlib.h>
int main()
{
int T;
scanf("%d",&T);
while(T--!=0)
{
int H,M;
scanf("%d:%d",&H,&M);
if(M!=0)
printf("0\n");
else{
if(H+12>24)
printf("%d\n",H-12);
else
printf("%d\n",H+12);
}
}
system("pause");
}