import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto T = readln.chomp.to!int;
    while (T--) {
        auto X = readln.chomp.to!long;
        auto Y = 180L;
        auto G = gcd(X, Y);
        X /= G;
        Y /= G;
        if (Y - X == 1) {
            Y *= 2;
        }
        writeln(Y);
    }
}
