#include #include #include #include #include #include #include #include #include #include #include #include #define mem(a,b) memset(a,b,sizeof(a)) using namespace std; typedef long long ll; typedef unsigned int ui; const int maxn=505; const int Mod=1e9+7; const int INF=0x3f3f3f3f; const double eps=1e-8; char mp[44][44]; int main() { #ifndef ONLINE_JUDGE // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); #endif int T,n,m; scanf("%d",&T); while(T--){ scanf("%d %d",&n,&m); int s1=(n-2)*180,s2=(m-2)*180; double t1=s1*1.0/n,t2=s2*1.0/m; int d1=360/t1+1,d2=360/t2+1; bool flag=false; for (int i=0;i<=d1;i++) for (int j=0;j<=d2;j++) { double sum=i*t1+j*t2; if (abs(sum-360)