链接:https://codeforces.com/gym/103428
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long ll;
int main()
{
// system("chcp 65001");
cout.tie(0);
cin.tie(0);
// freopen("C:/Users/zhaochen/Desktop/input.txt", "r", stdin);
int T;
cin >> T;
while (T--)
{
ll a, b;
cin >> a >> b;
cout << 180 * b / __gcd(180 * b, a) - 1 << endl;
}
return 0;
}