#include using ll = long long; using i64 = ll; template Tp dec(Tp &i) { return --i; } template Tp inc(Tp &i) { return ++i; } using namespace std; void solve(int t_ = 0) { i64 a, b; cin >> a >> b; cout << (b * 180) / gcd(a, b * 180) - 1 << '\n'; } signed main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cerr << std::fixed << std::setprecision(6); int i_ = 0; int t_ = 0; std::cin >> t_; for (i_ = 0; i_ < t_; ++i_) solve(i_); return 0; }