/*
Find minimum angle between hour and minute hand.
Input:
The first line contains the number of test cases, T. T lines follow, each of which contains two integer Hour hand H and minute hand M .
Output:
Print the minimum angle between the hands.
Constraints
1<=T<=100
01<=H<=12
01<=M<=59
*/
#include <stdio.h>
int main()
{
int T,*h,*m,h_angle,m_angle,angle,i;
scanf("%d",&T);
h=(int*)malloc(T*sizeof(int));
m=(int*)malloc(T*sizeof(int));
for(i=0;i<T;i++){
scanf("%d %d",&h[i],&m[i]);
if (h[i] == 12) h[i] = 0;
if (m[i] == 60) m[i] = 0;
h_angle=0.5 * (h[i]*60 + m[i]);
m_angle=6*m[i];
angle=abs(h_angle-m_angle);
if(360-angle <angle) angle=360-angle;
printf("%d\n",angle);
}
return 0;
}
int main()
{
int T,*h,*m,h_angle,m_angle,angle,i;
scanf("%d",&T);
h=(int*)malloc(T*sizeof(int));
m=(int*)malloc(T*sizeof(int));
for(i=0;i<T;i++){
scanf("%d %d",&h[i],&m[i]);
if (h[i] == 12) h[i] = 0;
if (m[i] == 60) m[i] = 0;
h_angle=0.5 * (h[i]*60 + m[i]);
m_angle=6*m[i];
angle=abs(h_angle-m_angle);
if(360-angle <angle) angle=360-angle;
printf("%d\n",angle);
}
return 0;
}