You are given an angle $\text{ang}$. 

The Jury asks You to find such regular $n$-gon (regular polygon with $n$ vertices) that it has three vertices $a$, $b$ and $c$ (they can be non-consecutive) with $\angle{abc} = \text{ang}$ or report that there is no such $n$-gon. [Image] 

If there are several answers, print the minimal one. It is guarantied that if answer exists then it doesn't exceed $998244353$.


-----Input-----

The first line contains single integer $T$ ($1 \le T \le 180$) — the number of queries. 

Each of the next $T$ lines contains one integer $\text{ang}$ ($1 \le \text{ang} < 180$) — the angle measured in degrees. 


-----Output-----

For each query print single integer $n$ ($3 \le n \le 998244353$) — minimal possible number of vertices in the regular $n$-gon or $-1$ if there is no such $n$.


-----Example-----
Input
4
54
50
2
178

Output
10
18
90
180



-----Note-----

The answer for the first query is on the picture above.

The answer for the second query is reached on a regular $18$-gon. For example, $\angle{v_2 v_1 v_6} = 50^{\circ}$.

The example angle for the third query is $\angle{v_{11} v_{10} v_{12}} = 2^{\circ}$.

In the fourth query, minimal possible $n$ is $180$ (not $90$).

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Geometry

Complete search


Solutions:
import math
T = int(input())
for t in range(T):
	ang = int(input())
	n = 2
	while True:
		n += 1
		if n * ang > (n - 2) * 180:
			continue
		if ang * n % 180:
			continue
		k = n * ang // ((n - 2) * 90)
		if k >= n:
			continue
		break
	print(n)


import math as mt
import sys, string, bisect
input = sys.stdin.readline
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())

def dist(x, y, c, d):
	return (x - c) ** 2 + (y - d) ** 2

def circle(x1, y1, x2, y2, r1, r2):
	distSq = ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) ** 0.5
	if distSq + r2 <= r1:
		return True
	else:
		return False
n = I()
e = n
d = defaultdict(int)
i = 1
while i < 180:
	n = 3
	while n < 998244354:
		k = 180 / n
		if i % k == 0 and i // k < n - 1:
			d[i] = n
			break
		n += 1
	i += 1
for i in range(0, e):
	f = I()
	print(d[f])


import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for _ in range(int(input())):
	n = int(input())
	i = 3
	ans = -1
	while i <= 360:
		x = 180 / i
		if n * i % 180 == 0 and x * (i - 2) >= n:
			ans = i
			break
		i += 1
	print(ans)


def compute_gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
T = int(input())
while T:
	x = int(input())
	gcd = compute_gcd(180, x)
	if 180 % gcd > 0:
		print(-1)
	else:
		n = int(180 / gcd)
		if n * gcd == 180:
			y = x * n / 180
			if y == n - 1:
				n = 2 * n
		else:
			n = -1
		print(n)
	T -= 1


tc = int(input())
while tc != 0:
	a = int(input())
	n = 3
	tc -= 1
	if a == 180:
		print('-1')
		continue
	while True:
		z = 180 / n
		if a % z == 0 and a / z <= n - 2:
			break
		n += 1
	print(n)


from math import *
t = int(input())
for _ in range(t):
	k = int(input())
	if k <= 176:
		a = gcd(k, 180)
		n = 180 // a
		b = 180 // n
		c = 180 * (n - 2)
		c = c // n
		if k <= c and k >= b:
			pass
		else:
			n = 2 * n
	else:
		a = gcd(k, 360)
		n = 360 // a
	print(n)


import math
t = int(input())
for i in range(t):
	a = int(input())
	b = math.gcd(180, a)
	if b + a == 180:
		print(2 * 180 // b)
	else:
		print(180 // b)


t = int(input())
ang = [int(input()) for _ in range(t)]
INF = float('inf')
memo = [INF] * 181
for n in range(3, 181):
	for i in range(1, n - 1):
		angle = 180 * i // n
		if 180 * i % n == 0 and memo[angle] == INF:
			memo[angle] = n
memo[179] = 360
for deg in ang:
	if deg == 180:
		print(-1)
	else:
		print(memo[deg])


def hcfnaive(a, b):
	if b == 0:
		return a
	else:
		return hcfnaive(b, a % b)
n = int(input())
for i in range(n):
	a = int(input())
	if 180 % (180 - a) == 0:
		print(2 * 180 // (180 - a))
	else:
		print(180 // hcfnaive(180, a))


ans = [180, 90, 60, 45, 36, 30, 180, 45, 20, 18, 180, 15, 180, 90, 12, 45, 180, 10, 180, 9, 60, 90, 180, 15, 36, 90, 20, 45, 180, 6, 180, 45, 60, 90, 36, 5, 180, 90, 60, 9, 180, 30, 180, 45, 4, 90, 180, 15, 180, 18, 60, 45, 180, 10, 36, 45, 60, 90, 180, 3, 180, 90, 20, 45, 36, 30, 180, 45, 60, 18, 180, 5, 180, 90, 12, 45, 180, 30, 180, 9, 20, 90, 180, 15, 36, 90, 60, 45, 180, 4, 180, 45, 60, 90, 36, 15, 180, 90, 20, 9, 180, 30, 180, 45, 12, 90, 180, 5, 180, 18, 60, 45, 180, 30, 36, 45, 20, 90, 180, 6, 180, 90, 60, 45, 36, 10, 180, 45, 60, 18, 180, 15, 180, 90, 8, 45, 180, 30, 180, 9, 60, 90, 180, 10, 36, 90, 60, 45, 180, 12, 180, 45, 20, 90, 36, 15, 180, 90, 60, 18, 180, 20, 180, 45, 24, 90, 180, 30, 180, 36, 40, 45, 180, 60, 72, 90, 120, 180, 360, -1]
t = int(input())
for _ in range(0, t):
	ang = int(input())
	print(ans[ang - 1])


T = int(input())
ansL = []
for i in range(T):
	x = int(input())
	for j in range(3, 361):
		if x * j % 180 == 0 and j - 2 >= x * j / 180:
			ansL.append(j)
			break
for z in ansL:
	print(z)


from math import ceil
t = int(input())

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
for i in range(t):
	ang = int(input())
	gcdd = gcd(180, ang)
	a = 180 // gcdd
	b = ang // gcdd
	print(a * ceil((b + 2) / a))


import math
n = int(input())
sol = []
for i in range(n):
	a = int(input())
	p = a // math.gcd(180, a)
	x = p
	q = 180 // math.gcd(180, a)
	n = x * q // p
	while True:
		if 1 <= x <= n - 2:
			break
		x += p
		n = x * q // p
	sol.append(n)
print(*sol, sep='\n')


d = {1: 180, 2: 90, 3: 60, 4: 45, 5: 36, 6: 30, 7: 180, 8: 45, 9: 20, 10: 18, 11: 180, 12: 15, 13: 180, 14: 90, 15: 12, 16: 45, 17: 180, 18: 10, 19: 180, 20: 9, 21: 60, 22: 90, 23: 180, 24: 15, 25: 36, 26: 90, 27: 20, 28: 45, 29: 180, 30: 6, 31: 180, 32: 45, 33: 60, 34: 90, 35: 36, 36: 5, 37: 180, 38: 90, 39: 60, 40: 9, 41: 180, 42: 30, 43: 180, 44: 45, 45: 4, 46: 90, 47: 180, 48: 15, 49: 180, 50: 18, 51: 60, 52: 45, 53: 180, 54: 10, 55: 36, 56: 45, 57: 60, 58: 90, 59: 180, 60: 3, 61: 180, 62: 90, 63: 20, 64: 45, 65: 36, 66: 30, 67: 180, 68: 45, 69: 60, 70: 18, 71: 180, 72: 5, 73: 180, 74: 90, 75: 12, 76: 45, 77: 180, 78: 30, 79: 180, 80: 9, 81: 20, 82: 90, 83: 180, 84: 15, 85: 36, 86: 90, 87: 60, 88: 45, 89: 180, 90: 4, 91: 180, 92: 45, 93: 60, 94: 90, 95: 36, 96: 15, 97: 180, 98: 90, 99: 20, 100: 9, 101: 180, 102: 30, 103: 180, 104: 45, 105: 12, 106: 90, 107: 180, 108: 5, 109: 180, 110: 18, 111: 60, 112: 45, 113: 180, 114: 30, 115: 36, 116: 45, 117: 20, 118: 90, 119: 180, 120: 6, 121: 180, 122: 90, 123: 60, 124: 45, 125: 36, 126: 10, 127: 180, 128: 45, 129: 60, 130: 18, 131: 180, 132: 15, 133: 180, 134: 90, 135: 8, 136: 45, 137: 180, 138: 30, 139: 180, 140: 9, 141: 60, 142: 90, 143: 180, 144: 10, 145: 36, 146: 90, 147: 60, 148: 45, 149: 180, 150: 12, 151: 180, 152: 45, 153: 20, 154: 90, 155: 36, 156: 15, 157: 180, 158: 90, 159: 60, 160: 18, 161: 180, 162: 20, 163: 180, 164: 45, 165: 24, 166: 90, 167: 180, 168: 30, 169: 180, 170: 36, 171: 40, 172: 45, 173: 180, 174: 60, 175: 72, 176: 90, 177: 120, 178: 180, 179: 360}
t = int(input())
for i in range(t):
	n = int(input())
	print(d[n])


from math import gcd
n = int(input())
for i in range(n):
	ang = int(input())
	nod = gcd(ang, 180)
	n = 180 // nod
	k = ang // nod
	if k == n - 1:
		print(2 * n)
	else:
		print(n)


t = int(input())
for i in range(t):
	ang = int(input())
	for n in range(3, 100001):
		a = 180 * (n - 2) / n
		if ang * (n - 2) % a == 0 and ang != 180 - 180 / n:
			print(n)
			break
		elif n == 100000:
			print(-1)


def gcd(a, b):
	return a if b == 0 else gcd(b, a % b)
t = int(input())
while t:
	a = int(input())
	d = gcd(180, a)
	n = int(180 / d)
	k = int(a / d)
	if k == n - 1:
		n *= 2
	print(n)
	t = t - 1


def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
t = int(input())
for i in range(t):
	x = int(input())
	a = 180 // gcd(x, 180)
	b = x // gcd(x, 180)
	if x == 180:
		print(-1)
	elif a == b + 1:
		print(2 * a)
	else:
		print(a)


from math import gcd
for _ in range(int(input())):
	t = int(input())
	k = gcd(t, 180)
	n = 180 // k
	if n * t // 180 > n - 2:
		n *= 2
	print(n)


import sys
prev = {}

def mprint(ang):
	if ang in prev:
		print(prev[ang])
		return
	for i in range(3, 361):
		for j in range(1, i - 1):
			if abs(j * 180 / i - ang) < 1e-06:
				print(i)
				prev[ang] = i
				return
t = int(input())
for i in range(t):
	ang = float(input())
	mprint(ang)


from math import gcd
T = int(input())
for t in range(T):
	ang = int(input())
	g = gcd(180, ang)
	n = 180 // g
	k = ang // g
	if k + 1 == n:
		n *= 2
		k *= 2
	print(n)


import math as ma
t = int(input())
for i in range(t):
	a = int(input())
	gg = ma.gcd(a, 180)
	hh = 180 // gg
	xx = a // gg
	if hh - xx <= 1:
		print(hh * 2)
	else:
		print(hh)


from math import gcd

def mnogougolnik(n, angles):
	result = []
	for i in range(n):
		great_div = gcd(180, angles[i])
		sides = 180 // great_div
		if angles[i] > (sides - 2) * 180 // sides:
			sides = 2 * sides
		result.append(sides)
	return result
N = int(input())
a = list()
for j in range(N):
	em = int(input())
	a.append(em)
for elem in mnogougolnik(N, a):
	print(elem)


n = int(input())
l = []
for i in range(n):
	s = int(input())
	l.append(s)
for i in l:
	for j in range(1, 181):
		x = 180 / j
		a = [x * m - i for m in range(1, j - 1)]
		k = False
		for s in a:
			if abs(s) < 0.0001:
				k = True
		if k:
			print(j)
			break
	else:
		print('360')


n = int(input())
for item in range(n):
	a = int(input())
	for i in range(1, 998244353):
		p = 1
		if a % (180 / i) == 0 and 180 / i * (i - 2) >= a:
			print(i)
			p = 0
			break
	if p == 1:
		print(-1)


import math
amount = int(input())
for i in range(amount):
	angle = int(input()) * 2
	divisors = []
	for j in range(1, int(math.sqrt(angle)) + 1):
		if angle % j == 0:
			divisors.append(j)
			divisors.append(angle // j)
	max_ = -1
	for k in range(len(divisors)):
		if 360 % divisors[k] == 0:
			if divisors[k] > max_ and 360 // divisors[k] >= angle // divisors[k] + 2:
				max_ = divisors[k]
	if max_ == -1:
		print(-1)
	else:
		print(360 // max_)


from math import gcd
for i in range(int(input())):
	ang = int(input())
	if 180 - ang == gcd(ang, 180):
		print(360 // gcd(ang, 180))
	else:
		print(180 // gcd(ang, 180))


l = []
for i in range(3, 180):
	ma = (i - 2) * 180 / i
	mn = (180 - ma) / 2
	if int(mn) == mn:
		l.append((int(mn), int(ma), i))
ans1 = []
for _ in range(179):
	n = _ + 1
	(ans, flag) = (180, False)
	for j in range(len(l)):
		if n % l[j][0] == 0 and n >= l[j][0] and (n <= l[j][1]):
			ans = l[j][2]
			flag = True
			break
	if n is 179:
		ans1.append(360)
	else:
		ans1.append(ans)
(ans1[134], ans1[164], ans1[170], ans1[174], ans1[176]) = (8, 24, 40, 72, 120)
for _ in range(int(input())):
	print(ans1[int(input()) - 1])


GCD = lambda a, b: a if b == 0 else GCD(b, a % b)
for _ in range(int(input())):
	ang = int(input())
	g = GCD(180, ang)
	k = ang // g
	n = 180 // g
	if k == n - 1:
		print(360 // g)
	else:
		print(n)


from math import gcd
T = int(input())
for _ in range(T):
	n = int(input())
	ans = 180 // gcd(180, n)
	if 180 * (ans - 2) // ans < n:
		print(ans * 2)
	else:
		print(ans)


import math
T = int(input())
for _ in range(T):
	ang = int(input())
	d = math.gcd(180, ang)
	n = 180 // d
	k = ang // d
	if n == k + 1:
		n *= 2
	print(n)


n = int(input())
cl = [1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 18, 20, 24, 30, 36, 40, 45, 60, 72, 90, 120]
pl = []
for i in range(22):
	pl.append(180 - cl[i])
dic = {}

def func(x):
	if x in dic.keys():
		return dic[x]
	for i in range(3, 181):
		for c in range(i - 1):
			t = 2 * (x + c * 90) / (c + 2)
			if t in pl:
				e = int(360 // (180 - t))
				dic.update({x: e})
				return e
for i in range(n):
	print(func(int(input())))


from math import gcd
t = int(input())
for i in range(0, t):
	num = int(input())
	temp = gcd(180, num)
	n = 180 // temp
	k = num // temp
	if k + 1 == n:
		n *= 2
	print(n)


T = int(input())
for i in range(T):
	angle = int(input())
	for j in range(3, 361):
		if j * angle % 180 == 0 and j * angle // 180 <= j - 2:
			print(j)
			break


def mingon(angle):
	if angle == 90:
		return 4
	elif angle < 90:
		for i in range(1, 2 * angle + 1):
			if 360 % (2 * angle / i) == 0:
				return int(360 / (2 * angle / i))
	else:
		for i in range(2, 2 * (180 - angle) + 1):
			if 360 % (2 * (180 - angle) / i) == 0:
				return int(360 / (2 * (180 - angle) / i))
t = int(input())
for i in range(t):
	ang = int(input())
	print(mingon(ang))


def gcd(a, b):
	return a if b == 0 else gcd(b, a % b)
for T in range(int(input())):
	de = int(input())
	g = gcd(de, 180)
	if int(de / g) == int(180 / g) - 1:
		print(int(180 / g) * 2)
	else:
		print(int(180 / g))


T = int(input())

def gcd(x, y):
	if y == 0:
		return x
	else:
		return gcd(y, x % y)
for _ in range(T):
	ang = int(input())
	d = gcd(180, ang)
	n = 180 // d
	if d == 180 - ang:
		n *= 2
	print(n)


import sys
T = int(sys.stdin.readline().strip())
for t in range(0, T):
	ang = int(sys.stdin.readline().strip())
	n = 180
	if ang % 2 == 0:
		ang = ang // 2
		n = n // 2
	if ang % 2 == 0:
		ang = ang // 2
		n = n // 2
	if ang % 5 == 0:
		ang = ang // 5
		n = n // 5
	if ang % 3 == 0:
		ang = ang // 3
		n = n // 3
	if ang % 3 == 0:
		ang = ang // 3
		n = n // 3
	if n == ang + 1:
		n = n * 2
		ang = ang * 2
	print(n)


T = int(input())
Q = [int(input()) for i in range(T)]
LIST = [None] * 181
for i in range(3, 361):
	for k in range(1, i - 1):
		if 180 * k % i == 0 and LIST[180 * k // i] == None:
			LIST[180 * k // i] = i
LIST[180] = -1
for q in Q:
	print(LIST[q])


from math import gcd
T = int(input())
while T:
	T -= 1
	n = int(input())
	t = gcd(n, 180)
	x = 180 // t
	y = n // t
	if x == y + 1:
		print(2 * x)
	else:
		print(x)


def read(type=1):
	if type:
		file = open('input.dat', 'r')
		n = int(file.readline())
		for i in range(n):
			ang = int(file.readline())
			solve(ang)
		file.close()
	else:
		n = int(input().strip())
		for i in range(n):
			ang = int(input().strip())
			solve(ang)

def solve(ang):
	i = 3
	while i < 365:
		t = 180 / i
		q = ang / t
		if abs(q - int(q)) < 1e-07 and t * (i - 2) >= ang:
			print(i)
			return 0
		i += 1
read(0)


t = int(input())
for _ in range(t):
	ang = int(input())
	i = 3
	while True:
		if ang % (180 / i) == 0 and ang / (180 / i) <= i - 2:
			print(i)
			break
		i += 1
	else:
		print(-1)


EPS = 10 ** (-6)
d = range(1, 1000)
t = int(input())
for i in range(t):
	ang = int(input())
	for j in d:
		if abs(int(ang / (180 / j)) * (180 / j) - ang) <= EPS:
			if int(ang / (180 / j)) > j - 2:
				continue
			print(j)
			break
	else:
		print(-1)


def gcd(a, b):
	while a != 0 and b != 0:
		if a > b:
			a = a % b
		else:
			b = b % a
	return a + b
t = int(input())
for i in range(t):
	ang = int(input())
	g = gcd(ang, 180)
	k = (2 * g + 180 - ang - 1) // (180 - ang)
	print(180 // g * k)


def solve():
	t = int(input())
	for tt in range(t):
		n = int(input())
		for i in range(3, 1801):
			for j in range(1, i - 1):
				if n == 180.0 * j / i:
					print(i)
					n = 0
					break
			if n == 0:
				break
solve()


T = int(input())
A = [int(input()) for i in range(T)]
mem = [[] for i in range(361)]
for n in range(3, 361):
	s = (n - 2) * 180 / n
	mem[n] = [s * i / (n - 2) for i in range(1, n - 1)]
eps = 1e-12

def solve(a):
	for n in range(3, 361):
		for m in mem[n]:
			if a - eps < m < a + eps:
				return n
for a in A:
	print(solve(a))


for _ in range(int(input())):
	n = int(input())
	for i in range(3, 10001):
		deg = 180 / i
		if n % deg == 0 and n <= (i - 2) * deg:
			print(i)
			break


itog = [180, 90, 60, 45, 36, 30, 180, 45, 20, 18, 180, 15, 180, 90, 12, 45, 180, 10, 180, 9, 60, 90, 180, 15, 36, 90, 20, 45, 180, 6, 180, 45, 60, 90, 36, 5, 180, 90, 60, 9, 180, 30, 180, 45, 4, 90, 180, 15, 180, 18, 60, 45, 180, 10, 36, 45, 60, 90, 180, 3, 180, 90, 20, 45, 36, 30, 180, 45, 60, 18, 180, 5, 180, 90, 12, 45, 180, 30, 180, 9, 20, 90, 180, 15, 36, 90, 60, 45, 180, 4, 180, 45, 60, 90, 36, 15, 180, 90, 20, 9, 180, 30, 180, 45, 12, 90, 180, 5, 180, 18, 60, 45, 180, 30, 36, 45, 20, 90, 180, 6, 180, 90, 60, 45, 36, 10, 180, 45, 60, 18, 180, 15, 180, 90, 8, 45, 180, 30, 180, 9, 60, 90, 180, 10, 36, 90, 60, 45, 180, 12, 180, 45, 20, 90, 36, 15, 180, 90, 60, 18, 180, 20, 180, 45, 24, 90, 180, 30, 180, 36, 40, 45, 180, 60, 72, 90, 120, 180, 360]
n = int(input())
for i in range(n):
	k = int(input())
	print(itog[k - 1])


T = int(input())
a = []
for i in range(3, 361):
	a.append(180 / i)
for i in range(T):
	k = int(input())
	for i in range(len(a)):
		if abs(k / a[i] - k // a[i]) < 10 ** (-10) and k != 180 - a[i]:
			print(i + 3)
			break


from fractions import Fraction
n = int(input())
final_numbers = list()
for _ in range(n):
	angle = int(input())
	f = Fraction(180, angle)
	if f.denominator <= f.numerator - 2:
		final_numbers.append(f.numerator)
	else:
		final_numbers.append(2 * f.numerator)
for elem in final_numbers:
	print(elem)


n = int(input())
for i in range(n):
	a = int(input())
	if a == 179:
		print(360)
		continue
	result = 10 ** 18
	for j in range(1, a + 1):
		k = a / j
		if a % k == 0:
			if 180 % k == 0:
				if a // k <= 180 // k - 2:
					result = min(result, 180 // k)
	if result == 10 ** 18:
		print(-1)
	else:
		print(int(result))


for i in range(int(input())):
	(ang, ans) = (int(input()), float('inf'))
	for j in range(60, 180):
		n = 360 / (180 - j)
		if int(n) != n:
			continue
		n = int(n)
		if ang == j:
			ans = min(n, ans)
			continue
		if j % (n - 2) == 0:
			if ang % (j // (n - 2)) == 0 and j >= ang:
				ans = min(ans, n)
	if ans == float('inf'):
		ans = -1
	print(ans)


import time
from fractions import gcd
t = int(input())
ans = []
start = time.time()
for i in range(t):
	ang = int(input())
	g = gcd(180, ang)
	n = 180 // g
	k = ang // g
	if k == n - 1:
		n *= 2
	ans.append(n)
for i in range(t):
	print(ans[i])
finish = time.time()


import math
for nt in range(int(input())):
	n = int(input())
	g = math.gcd(n, 180)
	k = n // g
	ans = 180 // g
	if k + 1 == ans:
		print(2 * ans)
	else:
		print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
for i in range(int(input())):
	n = int(input())
	g = math.gcd(n, 180)
	if n // g < 180 // g - 1:
		print(180 // g)
	else:
		print(360 // g)


for _ in range(int(input())):
	ang = int(input())
	i = 2
	d = {}
	angle = ang
	while i * i <= ang:
		count = 0
		while ang % i == 0:
			count += 1
			ang //= i
		if count > 0:
			d[i] = count
		i += 1
	if ang > 1:
		d[ang] = 1
	ans = 1
	two = d.get(2, 0)
	three = d.get(3, 0)
	five = d.get(5, 0)
	ans = ans * max(1, 2 ** (2 - two)) * max(1, 3 ** (2 - three)) * max(1, 5 ** (1 - five))
	k = max(1, ans)
	if k < 3:
		print(2 * k)
		continue
	if angle * k // 180 > k - 2:
		print(2 * k)
	else:
		print(k)


def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
import math
mp = {}
for i in range(3, 200):
	num = (i - 2) * 180
	den = i
	if num % den == 0:
		mp[num // den] = i
for t in range(ii()):
	ang = ii()
	if ang == 179:
		ans = 360
	elif ang in mp:
		ans = mp[ang]
	else:
		ans = 180 // math.gcd(180, ang)
	print(ans)


n = int(input())
for i in range(n):
	x = int(input())
	if x != 179 and x != 135 and (x != 165) and (x != 171) and (x != 175) and (x != 177):
		for j in range(x, 0, -1):
			if x % j == 180 % j == 0:
				if x <= 180 - 2 * j:
					print(int(180 / j))
					break
	elif x == 179:
		print(360)
	elif x == 135:
		print(8)
	elif x == 165:
		print(24)
	elif x == 171:
		print(40)
	elif x == 175:
		print(72)
	elif x == 177:
		print(120)


T = int(input())
r = []
for i in range(T):
	ang = int(input())
	for j in range(3, 998244354):
		max_ang = (j - 2) * 180 / j
		min_ang = max_ang / (j - 2)
		if ang % min_ang == 0 and ang <= max_ang:
			r.append(str(j))
			break
print('\n'.join(r))


t = int(input())
for i in range(t):
	ang = int(input())
	for n in range(3, 361):
		a = 180 / n
		if ang % a == 0 and n - ang // a >= 2:
			print(n)
			break


n = int(input())

def getGCD(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def getMinDivisor(a):
	for val in range(2, int(a // 2) + 1):
		if a % val == 0:
			return val
	return a
vals = [0 for i in range(n)]
for i in range(n):
	vals[i] = int(input())
for val in vals:
	gcd = getGCD(180, val)
	num_sides = 180 // gcd
	sides_spanned = val // gcd
	if sides_spanned > num_sides - 2:
		num_sides = num_sides * 2
	print(num_sides)


import itertools
from collections import Counter

def read_nums():
	return [int(x) for x in input().split()]

def get_all_subsets(arr):
	combs = []
	for i in range(0, len(arr) + 1):
		listing = [list(x) for x in itertools.combinations(arr, i)]
		combs.extend(listing)
	return combs

def multiply_all(arr):
	res = 1
	for elem in arr:
		res *= elem
	return res

def get_possible_n(num):
	nums = get_multiples(num)
	res = []
	for subs in get_all_subsets(nums):
		res.append(multiply_all(subs))
	return sorted(list(set(res)))

def get_multiples(n):
	res = []
	while n > 1:
		for i in range(2, n + 1):
			if n % i == 0:
				res.append(i)
				n //= i
				break
	return res

def counter_to_list(c):
	res = []
	for (k, v) in c.items():
		for _ in range(v):
			res.append(k)
	return res

def main():
	t = int(input())
	for _ in range(t):
		angle = int(input())
		multiples = Counter(get_multiples(180)) - Counter(get_multiples(angle))
		n = multiply_all(counter_to_list(multiples))
		print_res(angle, n)

def print_res(angle, n):
	while 180 * (n - 2) / (n * angle) < 1:
		n *= 2
	print(n)

def get_result(angle, possible_n):
	for n in possible_n:
		if angle % (180 // n) == 0 and angle <= 180 * (n - 2) // n:
			return n
	return -1
main()


for _ in range(int(input())):
	n = int(input())
	for i in range(1, 361):
		x = 180 / i
		if n % x == 0:
			y = n // x
			if y < i - 1:
				print(i)
				break
	else:
		print(-1)


import math
for i in range(int(input())):
	ang = int(input())
	lowest = math.gcd(ang, 180)
	n = 180 // lowest
	if ang == 180 - 360 // (2 * n):
		print(2 * n)
	else:
		print(n)


from math import gcd
Max_vertex = 998244353
T = int(input())
out = []
for _ in range(T):
	arg = int(input())
	g = gcd(arg, 180)
	k = arg // g
	n = 180 // g
	if k == n - 1:
		k *= 2
		n *= 2
	if n > Max_vertex:
		print(-1)
	else:
		print(n)


import sys, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
import math
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def si():
	return input()

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
t = 1
t = int(input())
for _ in range(t):
	ang = ii()
	a = 180
	if ang % 2 == 0:
		ang //= 2
		a //= 2
	if ang % 2 == 0:
		ang //= 2
		a //= 2
	if ang % 3 == 0:
		ang //= 3
		a //= 3
	if ang % 3 == 0:
		ang //= 3
		a //= 3
	if ang % 5 == 0:
		ang //= 5
		a //= 5
	if ang <= a - 2:
		print(a)
	else:
		print(2 * a)


def nok(x, y):
	while y > 0 and x > 0:
		if x > y:
			x = x % y
		else:
			y = y % x
	return x + y
for _ in range(int(input())):
	a = int(input())
	l = nok(180, a)
	k = a / l
	n = 180 / l
	if n < 3:
		if n == 2:
			n *= 2
			k *= 2
		if n == 1:
			n *= 3
			k *= 3
	if n == k + 1:
		n *= 2
		k *= 2
	print(int(n))


from math import gcd
n = int(input())
for t in range(n):
	ang = int(input())
	if ang == 179:
		print(360)
	elif ang == 178:
		print(180)
	elif ang == 90:
		print(4)
	else:
		z = gcd(ang, 180)
		if 180 % (180 - ang) == 0:
			print(360 // z)
		else:
			print(180 // z)


t = int(input())
for _ in range(t):
	n = int(input())
	if n == 179:
		print(360)
		continue
	for m in range(3, 181):
		if n in map(lambda d: d // m, filter(lambda d: d % m == 0, [180 * k for k in range(1, m - 1)])):
			print(m)
			break


def polygon(angle):
	n = 998244353
	for i in range(3, n + 1):
		if angle % (180 / i) == 0 and angle <= 180 - 360 / i:
			return i
	return -1
number = int(input())
for i in range(number):
	n = int(input())
	print(polygon(n))


from math import gcd
n = int(input())
for i in range(n):
	k = int(input())
	u = 180 // gcd(180, k)
	if u - u * k // 180 < 2:
		u *= 2
	print(u)


def valid(_n, ang):
	return ang <= (_n - 2) * 180 / _n
n = int(input())
for _ in range(n):
	angle = int(input())
	a = 1
	N = 180 * a // angle
	while 180 * a % angle != 0 or not valid(N, angle):
		a += 1
		N = 180 * a // angle
	print(N)


from sys import stdout
from sys import stdin

def get():
	return stdin.readline().strip()

def getf(sp=' '):
	return [int(i) for i in get().split(sp)]

def put(a, end='\n'):
	stdout.write(str(a) + end)

def putf(a, sep=' ', end='\n'):
	stdout.write(sep.join([str(i) for i in a]) + end)

def solve(a):
	for n in range(3, 361):
		ai = 180.0 / n
		k = a // ai
		if ai * k == a and k < n - 1:
			return n
	return

def main():
	t = int(get())
	for i in range(t):
		put(solve(int(get())))
main()


def gcd(a, b):
	if a % b == 0:
		return b
	else:
		return gcd(b, a % b)
n = int(input())
for x in range(n):
	a = int(input())
	b = 180 // gcd(a, 180)
	if a == 180:
		print(-1)
		continue
	if abs(a // (180 // b) - b) == 1:
		print(b * 2)
	else:
		print(b)


n = int(input())
A = [int(input()) for i in range(n)]
Ang = list(range(3, 181)) + [360]
for a in A:
	for ang in Ang:
		if a * ang % 180 == 0 and a * ang // 180 <= ang - 2:
			print(ang)
			break
	else:
		print(1)


T = int(input())
for i in range(T):
	n = 3
	angles = int(input())
	while True:
		if angles % (180 / n) == 0 and (n - 2) * (180 / n) >= angles:
			print(n)
			break
		else:
			n += 1


for a0 in range(int(input())):
	t = int(input())
	flag = 0
	for n in range(2, 361):
		for k in range(1, n - 1):
			if k * 180 / t == n:
				flag = 1
				print(n)
				break
		if flag:
			break
	if flag == 0:
		print(-1)


T = int(input())
for _ in range(T):
	arg = int(input().strip())
	N = 3
	while 1:
		num = 2 * arg // (360 / N)
		if num < N - 1 and 2 * arg % (360 / N) == 0:
			break
		N += 1
	print(N)


for i in range(int(input())):
	n = int(input())
	fl = 0
	for i in range(3, 1000):
		an = 180 - 360 / i
		an1 = an / (i - 2)
		for j in range(1, i - 1):
			d = an1 * j
			if d == n:
				print(i)
				fl = 1
				break
		if fl == 1:
			break
	if fl == 0:
		print(-1)


def gcd(a, b):
	if not b:
		return a
	return gcd(b, a % b)
t = int(input())
for i in range(t):
	ang = int(input())
	g = gcd(ang, 180)
	n = 180 // g
	k = ang // g
	if k == n - 1:
		n *= 2
		k *= 2
	print(n)


t = int(input())
for i in range(t):
	ang = int(input())
	for n in range(3, 361):
		ang1 = 360.0 / (2 * n)
		tt = int(ang / ang1)
		while tt * 360 < ang * 2 * n:
			tt += 1
		while tt * 360 > ang * 2 * n:
			tt -= 1
		if tt <= n - 2 and tt * 360 == ang * 2 * n:
			print(n)
			break


import math
T = int(input())
for i in range(T):
	n = int(input())
	x = math.gcd(180, n)
	n = n // x
	a = 180 // x
	if n == a - 1:
		print(2 * a)
	else:
		print(a)


ans = [-1 for x in range(180 + 1)]
for i in range(3, 361):
	start = (i - 2) * 180 / i
	if start != int(start):
		continue
	x = (180 - start) / 2
	for j in range(1, i - 1):
		if x * j == int(x * j) and ans[int(x * j)] == -1:
			ans[int(x * j)] = i
n = int(input())
for _ in range(n):
	y = int(input())
	print(ans[y])


min_counts = {}
for N in range(3, 361):
	angles = []
	alpha = 180 / N
	for k in range(1, N - 1):
		angle = alpha * k
		int_angle = int(angle)
		if int_angle == angle:
			if int_angle not in min_counts:
				min_counts[int_angle] = N
T = int(input())
for _ in range(T):
	query = int(input())
	print(min_counts[query])


d = {}
for i in range(1, 180):
	for j in range(3, 100001):
		if 2 * i / (360 / j) == 2 * i // (360 / j) and i <= (j - 2) * 180 // j:
			d[i] = j
			break
d[179] = 360
d[178] = 180
for _ in range(int(input())):
	print(d.get(int(input()), -1))


t = int(input())
for _ in range(t):
	n = int(input())
	e = 3
	while True:
		min_arg = 360 / (2 * e)
		max_arg = (e - 2) * 180 / e
		if n * e % 180 == 0 and n <= max_arg:
			print(e)
			break
		e += 1


prime = 998244353
t = int(input())
D = {}
for i in range(3, 361):
	interior = (i - 2) * 180 / i
	for j in range(3, i + 1):
		tmp = interior / (i - 2) * (j - 2)
		if tmp not in D:
			D[tmp] = i
for test in range(t):
	n = int(input())
	if n in D:
		print(D[n])
	else:
		print(-1)


import math
q = input()
q = int(q)
for i in range(q):
	ang = input()
	ang = int(ang)
	for k in range(3, 720):
		arc = 360 / k
		if 2 * ang % arc == 0 and 2 * ang / arc < k - 1:
			print(k)
			break


from math import gcd
t = int(input())
for i in range(t):
	n = int(input())
	p = gcd(180, n)
	if p + n == 180:
		print(360 // p)
	else:
		print(180 // p)


from math import gcd
from sys import stdin
for tc in range(int(input())):
	for line in stdin.readlines():
		line = int(line)
		n = 360 // gcd(360, int(line) * 2)
		mul = 1
		while line * (n * 2 * mul) // 360 > mul * n - 2:
			mul += 1
		print(n * mul)


import math
for i in range(int(input())):
	a = int(input())
	x = math.gcd(a, 180)
	ans = 180 // x
	if a == 180 - 360 // (2 * ans):
		print(2 * ans)
	else:
		print(ans)


import math
n = int(input())
for i in range(n):
	angle = int(input())
	gcd = math.gcd(180, angle)
	sides = 180 // gcd
	if angle > (sides - 2) * 180 // sides:
		sides = 2 * sides
	print(sides)


import sys
n_samples = int(sys.stdin.readline().strip())
angs = []
for idx in range(n_samples):
	angs.append(int(sys.stdin.readline().strip()))
min_n = 3
max_n = 998244353
for ang in angs:
	for n in range(min_n, max_n + 1):
		min_ang = 180 / n
		if ang < min_ang or ang > min_ang * (n - 2):
			continue
		if ang % min_ang == 0.0:
			print(n)
			break


ans = [0] * 180
for i in range(3, 361):
	angle = 180 / i
	for x in range(1, i - 1):
		ang = angle * x
		if ang == int(ang):
			if not ans[int(ang)]:
				ans[int(ang)] = i
for _ in range(int(input())):
	print(ans[int(input())])


l1 = []
for i in range(0, 180):
	l1.append(180 / (i + 1))
for i in range(0, int(input())):
	n = int(input())
	flag = 0
	for item in l1:
		if n % item == 0 and item * (l1.index(item) - 1) >= n:
			print(l1.index(item) + 1)
			flag = 1
			break
	if flag == 0:
		print(360)


t = int(input())
while t != 0:
	ang = int(input())
	f = 0
	ans = -1
	for n in range(3, 1000):
		for k in range(1, n - 1):
			if 180 / n * k == ang:
				ans = n
				f = 1
				break
		if f == 1:
			break
	print(ans)
	t -= 1


from fractions import gcd
for _ in range(int(input())):
	ang = int(input())
	g = gcd(ang, 180)
	k = ang // g
	n = 180 // g
	if k + 1 == n:
		k *= 2
		n *= 2
	print(n)


t = int(input())
for i in range(t):
	ang = int(input())
	if ang == 179:
		print(360)
		continue
	for n in range(3, 181):
		if ang * n % 180 == 0 and ang * n // 180 < n - 1:
			print(n)
			break


t = int(input())
for z in range(t):
	n = int(input())
	for i in range(3, 361):
		q = 0
		for j in range(1, i - 1):
			if 180 * j % n == 0 and 180 * j / n == i:
				print(i)
				q = 1
				break
		if q == 1:
			break


import math
count = 0
for i in range(150):
	count += 1
for i in range(int(input())):
	a = int(input())
	x = math.gcd(a, 180)
	ans = 180 // x
	if a == 180 - 360 // (2 * ans):
		print(2 * ans)
	else:
		print(ans)


import math
from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	ang = int(stdin.readline())
	d = math.gcd(180, ang)
	n = 180 / d
	k = ang / d
	k = int(k)
	n = int(n)
	if k == n - 1:
		n *= 2
	print(n)


dp = [0] * 190
for a in range(1, 180):
	f = 0
	for i in range(3, 3000):
		k = (180 - 360 / i) / (i - 2)
		for j in range(1, i - 1):
			if k * j == a:
				f = 1
				dp[a] = i
				break
		if f == 1:
			break
for _ in range(int(input())):
	ang = int(input())
	if dp[ang] == 0:
		print('-1')
	else:
		print(dp[ang])


t = int(input())

def computeGCD(x, y):
	if x > y:
		small = y
	else:
		small = x
	for i in range(1, small + 1):
		if x % i == 0 and y % i == 0:
			gcd = i
	return gcd
while t:
	t -= 1
	ang = int(input())
	ang = 2 * ang
	ans = computeGCD(ang, 360)
	ans = 360 / ans
	x = ang * ans / 360
	if x > ans - 2:
		ans *= 2
	print(int(ans))


import math
t = int(input())
for e in range(t):
	n = int(input())
	g = math.gcd(n, 180)
	p = n // g
	q = 180 // g
	if n == 180 or n == 0:
		print(-1)
	elif p == q - 1:
		print(2 * q)
	else:
		print(q)


from math import gcd
for _ in range(int(input())):
	ang = int(input())
	_gdc = gcd(180, ang)
	k = ang // _gdc
	n = 180 // _gdc
	print(n * 2 if k + 1 == n else n)


def mi():
	return map(int, input().split())
from math import ceil as f

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
for _ in range(int(input())):
	n = int(input())
	t1 = t3 = 180 / n
	i1 = 1
	t4 = gcd(180, n)
	if t4 != n:
		nr = 180 // gcd(180, n)
		dr = n // gcd(180, n)
		t1 = nr
	(t2, t3) = (180 - n, t1)
	if f(t1 * i1) != int(t1 * i1):
		print(-1)
		continue
	while t2 <= 180 / t1:
		t1 += t3
	print(f(t1))


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify, nlargest
from copy import deepcopy
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))

def inpl_1():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))

def inps():
	return sys.stdin.readline()

def inpsl(x):
	tmp = sys.stdin.readline()
	return tmp[:x]

def err(x):
	print(x)
	exit()
for _ in range(inp()):
	ang = inp()
	res = -1
	for n in range(3, 1000):
		for k in range(1, n - 1):
			if 180 * k == ang * n:
				res = n
				break
		if res != -1:
			break
	print(res)


import math
n = int(input())
for i in range(n):
	arg = int(input())
	k = 180 / math.gcd(180, arg)
	i = arg / math.gcd(180, arg)
	if k - 1 == i:
		print(int(2 * k))
	else:
		print(int(k))


import sys

def solve(io):
	T = io.read_int()
	for _ in range(0, T):
		A = io.read_int()
		ans = -1
		for s in range(3, 361):
			for i in range(1, s - 1):
				if 180 * i % s == 0 and 180 * i / s == A:
					ans = s
					break
			if ans > 0:
				break
		io.println(ans)

class IO:
	in_stream = None
	out_stream = None
	raw = ''
	buf = []
	pos = 0

	def __init__(self, input_stream, output_stream):
		self.in_stream = input_stream
		self.out_stream = output_stream

	def read_to_buffer(self):
		self.raw = self.in_stream.readline().rstrip('\n')
		self.buf = self.raw.split()
		self.pos = 0

	def read_string(self):
		while self.pos == len(self.buf):
			self.read_to_buffer()
		ans = self.buf[self.pos]
		self.pos += 1
		return ans

	def read_int(self):
		return int(self.read_string())

	def read_float(self):
		return float(self.read_string())

	def read_string_array(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.read_string())
		return arr

	def read_int_array(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.read_int())
		return arr

	def read_float_array(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.read_float())
		return arr

	def read_line(self):
		while self.pos == len(self.buf):
			self.read_to_buffer()
		if self.pos > 0:
			raise ValueError('Cannot call read_line in the middle of a line.')
		self.pos = len(self.buf)
		return self.raw

	def print(self, *args):
		self.out_stream.write(' '.join([str(x) for x in args]))

	def println(self, *args):
		self.print(*args)
		self.print('\n')

	def println_array(self, arr, sep=' '):
		self.println(sep.join((str(x) for x in arr)))

	def flush_output(self):
		self.out_stream.flush()
pythonIO = IO(sys.stdin, sys.stdout)
solve(pythonIO)
pythonIO.flush_output()


t = int(input())
while t:
	n = int(input())
	k = 3
	while not (n % (180 / k) == 0 and (k - 2) * (180 / k) >= n):
		k += 1
	print(k)
	t -= 1


from math import gcd
for _ in range(int(input())):
	t = int(input())
	if t == 180:
		print(-1)
	else:
		g = gcd(t, 180)
		(n, d) = (t // g, 180 // g)
		if not 1 <= n <= d - 2:
			d *= 2
			n *= 2
		print(d if 1 <= n <= d - 2 else -1)


for _ in range(int(input())):
	ang = int(input())
	n = 3
	f = 0
	while (n - 2) * 180 / n <= 179:
		if ang <= (n - 2) * 180 / n and ang % ((n - 2) * 180 / (n * (n - 2))) == 0:
			f = 1
			break
		else:
			n += 1
	if f:
		print(n)
	else:
		print(-1)


import math
T = int(input())
for _ in range(T):
	ang = int(input())
	b = math.gcd(180, ang)
	ans = 180 // b
	if ans * ang // 180 > ans - 2:
		ans *= 2
	print(ans)


import math
t = int(input())
while t > 0:
	t = t - 1
	ang = int(input())
	n = math.ceil(360 / (180 - ang))
	for i in range(n, 361):
		num = 180 / i
		total = num * (i - 2)
		if (total - ang) % num == 0:
			print(i)
			break


for _ in range(int(input())):
	arg = 2 * int(input())
	l = 3
	ans = -1
	while l <= 360:
		degree = 360 / l
		if arg % degree == 0 and arg // degree != l - 1:
			ans = l
			break
		l += 1
	print(ans)


for i in range(int(input())):
	n = int(input())
	f = 1
	for j in range(1, 10000, 1):
		if n <= (j - 2) * 180 / j and n * j / 180 == int(n * j / 180):
			f = 0
			print(j)
			break
	if f:
		print('-1')


def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
t = int(input())
for p in range(t):
	ang = int(input())
	centre_ang = 2 * ang
	k = gcd(360, centre_ang)
	if k == 1:
		print(-1)
	else:
		ans = 360 // k
		rem = 180 - ang
		if rem >= 360 // ans:
			print(ans)
		else:
			print(ans * 2)


import math
for i in range(int(input())):
	angle = int(input()) * 2
	x = math.gcd(angle, 360)
	(a, b) = (angle // x, 360 // x)
	while b - a < 2:
		(a, b) = (a * 2, b * 2)
	print(b)


from math import *
from itertools import *
from collections import *
from bisect import *

def find(ang):
	g = gcd(180, ang)
	k = ang // g
	n = 180 // g
	if k + 1 == n:
		n <<= 1
	return n
T = int(input())
for _ in range(T):
	ang = int(input())
	print(find(ang))


from math import *
T = int(input())
for i in range(T):
	a = int(input())
	g = gcd(180, a)
	n = 180 // g
	u = (360 + 180 - a - 1) // (180 - a)
	n = (u + n - 1) // n * n
	print(n)


from math import gcd
t = int(input())
for i in range(t):
	res = int(input())
	if res == 90:
		print(4)
	elif res < 90:
		value = int(180 / gcd(180, res))
		print(value)
	elif 360 % (360 - 2 * res) == 0:
		value = int(720 / gcd(360, 360 - 2 * res))
		print(value)
	else:
		value = int(360 / gcd(360, 360 - 2 * res))
		print(value)


t = int(input())
for i in range(t):
	ans = -1
	an = int(input())
	for i in range(3, 800):
		for j in range(1, i - 1):
			if 180 * j % i == 0:
				k = 180 * j // i
				if k == an:
					ans = i
					break
		if ans != -1:
			break
	print(ans)


def gcd(a, b):
	if b % a == 0:
		return a
	return gcd(b % a, a)
n = int(input())
for i in range(n):
	a = int(input())
	b = 180 // gcd(a, 180)
	c = b
	while a // (180 / b) > b - 2:
		b += c
	print(b)


d = []
for i in range(3, 1000):
	b = set([])
	a = 180 - 360 / i
	a = a / (i - 2)
	for j in range(1, i - 1):
		c = a * j
		if c == int(c):
			b.add(int(c))
	d.append(b)
t = int(input())
for _ in range(t):
	n = int(input())
	for i in range(len(d)):
		if n in d[i]:
			print(i + 3)
			break


def nod(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return a
for _ in range(int(input())):
	angle = int(input())
	d = nod(180, angle)
	n = 180 // d
	x = angle // d
	if n - x < 2:
		n *= 2
		x = angle * n // 180
	print(n if n - x >= 2 else -1)


import math
T = int(input())
for _ in range(T):
	ang = int(input())
	t = math.gcd(ang, 180)
	possiblek = ang // t
	possiblen = 180 // t
	if possiblek <= possiblen - 2:
		print(possiblen)
	else:
		print(possiblen * 2)


def factors(n):
	i = 2
	blanck = []
	while i ** 2 <= n:
		if n % i == 0:
			blanck.append(i)
			n //= i
		else:
			i += 1
	if n > 1:
		blanck.append(n)
		n = 1
	return blanck

def side(n):
	x = factors(n)
	i = 0
	base = 180
	x = sorted(x, reverse=True)
	while i < len(x) and base >= 3:
		if base % x[i] == 0 and base // x[i] >= 3:
			base = base // x[i]
			i += 1
		else:
			i += 1
	if 180 * (base - 2) // base < n:
		base *= 2
	return base
for i in range(int(input())):
	print(side(int(input())))


def gcd(a, b):
	if a == 0 or b == 0:
		return max(a, b)
	return gcd(b, a % b)
t = int(input())
for _ in range(t):
	ang = int(input())
	gc = gcd(180, ang)
	n = 180 // gc
	if ang // gc + 1 == n:
		n *= 2
	print(n)


import math
t = int(input())
for i in range(t):
	cur = int(input())
	temp = math.gcd(cur, 180)
	if cur == 180 - temp:
		print(360 // temp)
	else:
		print(180 // temp)


T = int(input())
i = [None] * T
res = 0
for x in range(T):
	i[x] = int(input())
for x in range(T):
	n = 1
	while True:
		if i[x] % float(180 / n) == 0:
			if 180 - float(360 / n) < i[x]:
				n = n + 1
				continue
			res = n
			break
		else:
			n = n + 1
	print(res)


from sys import stdin, stdout
from math import *
from heapq import *
from collections import *

def main():
	T = int(stdin.readline())
	for _ in range(T):
		ang = int(stdin.readline())
		res = -1
		for n in range(3, 1000):
			u = 360.0 / (2.0 * n)
			if floor(float(ang) / u) < n - 1 and floor(float(ang) / u) * u == float(ang):
				res = n
				break
		stdout.write(str(res) + '\n')
	return 0
main()


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
T = int(input())
for t in range(T):
	n = int(input())
	g = gcd(180, n)
	k = n // g
	s = 180 // g
	if k + 1 == s:
		k *= 2
		s *= 2
	print(s)


import math
for _ in range(int(input())):
	a = int(input())
	g = math.gcd(180, a)
	k = a // g
	n = 180 // g
	if k + 1 == n:
		n *= 2
	print(n)


T = int(input())
angle = {}
n = 2

def polygon(n):
	global angle
	now = []
	total = (n - 2) * 180
	one = total / n
	for i in range(n - 3):
		x = ((i + 1) * 180 - (i + 1) * one) / 2
		now.append(x)
		if x not in angle:
			angle[x] = n
	for i in range(len(now)):
		for k in range(i + 1, len(now)):
			if now[k] - now[i] not in angle:
				angle[now[k] - now[i]] = n

def inti(a):
	global it
	n = 360 / (180 - a)
	if n % 1 == 0:
		it = True
		return int(n)
for z in range(T):
	a = int(input())
	it = False
	m = inti(a)
	if it:
		print(m)
		continue
	while a not in angle:
		n += 1
		polygon(n)
	ta = angle[a]
	print(ta)


t = int(input())
for i in range(t):
	ang = int(input())
	temp = ang
	i = 2
	while 180 % temp != 0:
		temp = ang / i
		i += 1
	if temp + ang == 180:
		print(int(360 / temp))
	else:
		print(int(180 / temp))


import math
for i in range(int(input())):
	n = int(input())
	g = math.gcd(n, 180)
	if n // g < 180 // g - 1:
		print(180 // g)
	else:
		print(360 // g)


l = []
for i in range(3, 361):
	l.append([])
	x = 180 / i
	for j in range(1, i - 1):
		l[-1].append(x * j)
for _ in range(int(input())):
	x = int(input())
	flag = False
	for i in range(len(l)):
		if x in l[i]:
			print(i + 3)
			flag = True
			break
	if flag == False:
		print(-1)


def a(p, q):
	while q != 0:
		(p, q) = (q, p % q)
	return p
T = int(input())
degrees = [int(input()) for i in range(T)]
for u in degrees:
	m = a(180, u)
	if 180 - u == m:
		print(180 * 2 // m)
	else:
		print(180 // m)


t = int(input())
for testcase in range(0, t):
	n = int(input())
	ans = 3
	while ans * n % 180 or ans * n // 180 > ans - 2:
		ans += 1
	print(ans)


from math import gcd
for _ in range(int(input())):
	a = int(input())
	n = 180 // gcd(180, a)
	if 180 * (n - 2) < a * n:
		n *= 2
	print(n)


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	g = gcd(180, n)
	p = 180 // g
	q = n // g
	if q >= p - 1:
		print(2 * p)
	else:
		print(p)


t = int(input())
for i in range(t):
	theta = int(input())
	n = 3
	got = False
	while n <= 998244353:
		ls = []
		ang = (180 - 360 / n) / (n - 2)
		for i in range(n - 2):
			ls.append(ang * (i + 1))
		if theta in ls:
			got = True
			print(n)
			break
		n += 1
	if not got:
		print(-1)


import sys
import math

def funct(angel):
	min_angel = math.gcd(180, angel)
	n = 180 // min_angel
	if angel / 180 == (n - 1) / n:
		n *= 2
	return n

def main():
	n = int(sys.stdin.readline())
	for _ in range(n):
		angel = int(sys.stdin.readline())
		print(funct(angel))
main()


for _ in range(int(input())):
	(a, b) = (180, int(input()))
	b = a - b
	if (a - b) % b == b % b:
		a *= 2
	ibo = a
	while b:
		(a, b) = (b, a % b)
	print(ibo // a)


import math
import collections
import bisect
import heapq
import time
import itertools
import sys

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def solve(ang):
	g = gcd(ang, 180)
	k = ang // g
	n = 180 // g
	if k + 1 == n:
		k *= 2
		n *= 2
	return n
T = int(input())
for ti in range(T):
	ang = int(input())
	print(solve(ang))


def Euclidean_gcd(m, n):
	if n == 0:
		return m
	return Euclidean_gcd(n, m % n)
for _ in range(int(input())):
	ang = int(input())
	central_angle = 2 * ang
	gcd = Euclidean_gcd(360, central_angle)
	if gcd == 1:
		print(-1)
	else:
		min_vertices = 360 // gcd
		sum_of_other_angles = 180 - ang
		if sum_of_other_angles >= 360 // min_vertices:
			print(min_vertices)
		else:
			print(2 * min_vertices)


def gcd(x, y):
	gcd = 1
	if x % y == 0:
		return y
	else:
		gcd = int(y / 2)
		while gcd > 0:
			if x % gcd == 0 and y % gcd == 0:
				return gcd
			else:
				gcd -= 1
n = int(input())
for i in range(n):
	angle = int(input())
	x = gcd(angle, 180)
	answer = int(180 / x)
	small = int(angle / x)
	if answer - small == 1:
		answer *= 2
	print(answer)


t = int(input())
b = []
for i in range(t):
	ang = int(input())
	f = 0
	x = 3
	if ang == 179:
		b.append(360)
	else:
		while x < 181 and f == 0:
			for j in range(1, x - 1):
				if ang == j * 360 / (x * 2):
					f = 1
					b.append(x)
					break
			x += 1
		if f == 0:
			b.append(-1)
for i in range(len(b)):
	print(b[i])


n = int(input())
ans = [-1] * n
for j in range(n):
	x = int(input())
	for i in range(1, 998244353):
		p = i * 180.0 / x
		if p == int(p):
			if x * p * 1.0 == i * 180.0 and i <= p - 2:
				ans[j] = int(p)
				break
for i in range(n):
	print(ans[i])


T = int(input())
ang = [int(input()) for _ in range(T)]
for a in ang:
	for n in range(3, 181):
		if a % (180 / n) == 0:
			x = a // (180 / n)
			if n - 2 >= x:
				print(n)
				break
	else:
		print(360)


def divisors(M):
	d = []
	i = 1
	while M >= i ** 2:
		if M % i == 0:
			d.append(i)
			if i ** 2 != M:
				d.append(M // i)
		i = i + 1
	return d

def popcount(x):
	x = x - (x >> 1 & 1431655765)
	x = (x & 858993459) + (x >> 2 & 858993459)
	x = x + (x >> 4) & 252645135
	x = x + (x >> 8)
	x = x + (x >> 16)
	return x & 127

def eratosthenes(n):
	res = [0 for i in range(n + 1)]
	prime = set([])
	for i in range(2, n + 1):
		if not res[i]:
			prime.add(i)
			for j in range(1, n // i + 1):
				res[i * j] = 1
	return prime

def factorization(n):
	res = []
	for p in prime:
		if n % p == 0:
			while n % p == 0:
				n //= p
			res.append(p)
	if n != 1:
		res.append(n)
	return res

def euler_phi(n):
	res = n
	for x in range(2, n + 1):
		if x ** 2 > n:
			break
		if n % x == 0:
			res = res // x * (x - 1)
			while n % x == 0:
				n //= x
	if n != 1:
		res = res // n * (n - 1)
	return res

def ind(b, n):
	res = 0
	while n % b == 0:
		res += 1
		n //= b
	return res

def isPrimeMR(n):
	if n == 1:
		return 0
	d = n - 1
	d = d // (d & -d)
	L = [2, 3, 5, 7, 11, 13, 17]
	for a in L:
		t = d
		y = pow(a, t, n)
		if y == 1:
			continue
		while y != n - 1:
			y = y * y % n
			if y == 1 or t == n - 1:
				return 0
			t <<= 1
	return 1

def findFactorRho(n):
	from math import gcd
	m = 1 << n.bit_length() // 8
	for c in range(1, 99):
		f = lambda x: (x * x + c) % n
		(y, r, q, g) = (2, 1, 1, 1)
		while g == 1:
			x = y
			for i in range(r):
				y = f(y)
			k = 0
			while k < r and g == 1:
				ys = y
				for i in range(min(m, r - k)):
					y = f(y)
					q = q * abs(x - y) % n
				g = gcd(q, n)
				k += m
			r <<= 1
		if g == n:
			g = 1
			while g == 1:
				ys = f(ys)
				g = gcd(abs(x - ys), n)
		if g < n:
			if isPrimeMR(g):
				return g
			elif isPrimeMR(n // g):
				return n // g
			return findFactorRho(g)

def primeFactor(n):
	i = 2
	ret = {}
	rhoFlg = 0
	while i * i <= n:
		k = 0
		while n % i == 0:
			n //= i
			k += 1
		if k:
			ret[i] = k
		i += 1 + i % 2
		if i == 101 and n >= 2 ** 20:
			while n > 1:
				if isPrimeMR(n):
					(ret[n], n) = (1, 1)
				else:
					rhoFlg = 1
					j = findFactorRho(n)
					k = 0
					while n % j == 0:
						n //= j
						k += 1
					ret[j] = k
	if n > 1:
		ret[n] = 1
	if rhoFlg:
		ret = {x: ret[x] for x in sorted(ret)}
	return ret

def divisors(n):
	res = [1]
	prime = primeFactor(n)
	for p in prime:
		newres = []
		for d in res:
			for j in range(prime[p] + 1):
				newres.append(d * p ** j)
		res = newres
	res.sort()
	return res

def xorfactorial(num):
	if num == 0:
		return 0
	elif num == 1:
		return 1
	elif num == 2:
		return 3
	elif num == 3:
		return 0
	else:
		x = baseorder(num)
		return 2 ** x * ((num - 2 ** x + 1) % 2) + function(num - 2 ** x)

def xorconv(n, X, Y):
	if n == 0:
		res = [X[0] * Y[0] % mod]
		return res
	x = [X[i] + X[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	y = [Y[i] + Y[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	z = [X[i] - X[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	w = [Y[i] - Y[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	res1 = xorconv(n - 1, x, y)
	res2 = xorconv(n - 1, z, w)
	former = [(res1[i] + res2[i]) * inv for i in range(2 ** (n - 1))]
	latter = [(res1[i] - res2[i]) * inv for i in range(2 ** (n - 1))]
	former = list(map(lambda x: x % mod, former))
	latter = list(map(lambda x: x % mod, latter))
	return former + latter

def merge_sort(A, B):
	(pos_A, pos_B) = (0, 0)
	(n, m) = (len(A), len(B))
	res = []
	while pos_A < n and pos_B < m:
		(a, b) = (A[pos_A], B[pos_B])
		if a < b:
			res.append(a)
			pos_A += 1
		else:
			res.append(b)
			pos_B += 1
	res += A[pos_A:]
	res += B[pos_B:]
	return res

class UnionFindVerSize:

	def __init__(self, N):
		self._parent = [n for n in range(0, N)]
		self._size = [1] * N
		self.group = N

	def find_root(self, x):
		if self._parent[x] == x:
			return x
		self._parent[x] = self.find_root(self._parent[x])
		stack = [x]
		while self._parent[stack[-1]] != stack[-1]:
			stack.append(self._parent[stack[-1]])
		for v in stack:
			self._parent[v] = stack[-1]
		return self._parent[x]

	def unite(self, x, y):
		gx = self.find_root(x)
		gy = self.find_root(y)
		if gx == gy:
			return
		self.group -= 1
		if self._size[gx] < self._size[gy]:
			self._parent[gx] = gy
			self._size[gy] += self._size[gx]
		else:
			self._parent[gy] = gx
			self._size[gx] += self._size[gy]

	def get_size(self, x):
		return self._size[self.find_root(x)]

	def is_same_group(self, x, y):
		return self.find_root(x) == self.find_root(y)

class WeightedUnionFind:

	def __init__(self, N):
		self.parent = [i for i in range(N)]
		self.size = [1 for i in range(N)]
		self.val = [0 for i in range(N)]
		self.flag = True
		self.edge = [[] for i in range(N)]

	def dfs(self, v, pv):
		stack = [(v, pv)]
		new_parent = self.parent[pv]
		while stack:
			(v, pv) = stack.pop()
			self.parent[v] = new_parent
			for (nv, w) in self.edge[v]:
				if nv != pv:
					self.val[nv] = self.val[v] + w
					stack.append((nv, v))

	def unite(self, x, y, w):
		if not self.flag:
			return
		if self.parent[x] == self.parent[y]:
			self.flag = self.val[x] - self.val[y] == w
			return
		if self.size[self.parent[x]] > self.size[self.parent[y]]:
			self.edge[x].append((y, -w))
			self.edge[y].append((x, w))
			self.size[x] += self.size[y]
			self.val[y] = self.val[x] - w
			self.dfs(y, x)
		else:
			self.edge[x].append((y, -w))
			self.edge[y].append((x, w))
			self.size[y] += self.size[x]
			self.val[x] = self.val[y] + w
			self.dfs(x, y)

class Dijkstra:

	class Edge:

		def __init__(self, _to, _cost):
			self.to = _to
			self.cost = _cost

	def __init__(self, V):
		self.G = [[] for i in range(V)]
		self._E = 0
		self._V = V

	@property
	def E(self):
		return self._E

	@property
	def V(self):
		return self._V

	def add_edge(self, _from, _to, _cost):
		self.G[_from].append(self.Edge(_to, _cost))
		self._E += 1

	def shortest_path(self, s):
		import heapq
		que = []
		d = [10 ** 15] * self.V
		d[s] = 0
		heapq.heappush(que, (0, s))
		while len(que) != 0:
			(cost, v) = heapq.heappop(que)
			if d[v] < cost:
				continue
			for i in range(len(self.G[v])):
				e = self.G[v][i]
				if d[e.to] > d[v] + e.cost:
					d[e.to] = d[v] + e.cost
					heapq.heappush(que, (d[e.to], e.to))
		return d

def Z_algorithm(s):
	N = len(s)
	Z_alg = [0] * N
	Z_alg[0] = N
	i = 1
	j = 0
	while i < N:
		while i + j < N and s[j] == s[i + j]:
			j += 1
		Z_alg[i] = j
		if j == 0:
			i += 1
			continue
		k = 1
		while i + k < N and k + Z_alg[k] < j:
			Z_alg[i + k] = Z_alg[k]
			k += 1
		i += k
		j -= k
	return Z_alg

class BIT:

	def __init__(self, n, mod=None):
		self.BIT = [0] * (n + 1)
		self.num = n
		self.mod = mod

	def query(self, idx):
		res_sum = 0
		mod = self.mod
		while idx > 0:
			res_sum += self.BIT[idx]
			if mod:
				res_sum %= mod
			idx -= idx & -idx
		return res_sum

	def update(self, idx, x):
		mod = self.mod
		while idx <= self.num:
			self.BIT[idx] += x
			self.BIT[idx] %= mod
			idx += idx & -idx
		return

class dancinglink:

	def __init__(self, n, debug=False):
		self.n = n
		self.debug = debug
		self._left = [i - 1 for i in range(n)]
		self._right = [i + 1 for i in range(n)]
		self.exist = [True for i in range(n)]

	def pop(self, k):
		if self.debug:
			assert self.exist[k]
		L = self._left[k]
		R = self._right[k]
		if L != -1:
			if R != self.n:
				(self._right[L], self._left[R]) = (R, L)
			else:
				self._right[L] = self.n
		elif R != self.n:
			self._left[R] = -1
		self.exist[k] = False

	def left(self, idx, k=1):
		if self.debug:
			assert self.exist[idx]
		res = idx
		while k:
			res = self._left[res]
			if res == -1:
				break
			k -= 1
		return res

	def right(self, idx, k=1):
		if self.debug:
			assert self.exist[idx]
		res = idx
		while k:
			res = self._right[res]
			if res == self.n:
				break
			k -= 1
		return res

class SparseTable:

	def __init__(self, A, merge_func, ide_ele):
		N = len(A)
		n = N.bit_length()
		self.table = [[ide_ele for i in range(n)] for i in range(N)]
		self.merge_func = merge_func
		for i in range(N):
			self.table[i][0] = A[i]
		for j in range(1, n):
			for i in range(0, N - 2 ** j + 1):
				f = self.table[i][j - 1]
				s = self.table[i + 2 ** (j - 1)][j - 1]
				self.table[i][j] = self.merge_func(f, s)

	def query(self, s, t):
		b = t - s + 1
		m = b.bit_length() - 1
		return self.merge_func(self.table[s][m], self.table[t - 2 ** m + 1][m])

class BinaryTrie:

	class node:

		def __init__(self, val):
			self.left = None
			self.right = None
			self.max = val

	def __init__(self):
		self.root = self.node(-10 ** 15)

	def append(self, key, val):
		pos = self.root
		for i in range(29, -1, -1):
			pos.max = max(pos.max, val)
			if key >> i & 1:
				if pos.right is None:
					pos.right = self.node(val)
					pos = pos.right
				else:
					pos = pos.right
			elif pos.left is None:
				pos.left = self.node(val)
				pos = pos.left
			else:
				pos = pos.left
		pos.max = max(pos.max, val)

	def search(self, M, xor):
		res = -10 ** 15
		pos = self.root
		for i in range(29, -1, -1):
			if pos is None:
				break
			if M >> i & 1:
				if xor >> i & 1:
					if pos.right:
						res = max(res, pos.right.max)
					pos = pos.left
				else:
					if pos.left:
						res = max(res, pos.left.max)
					pos = pos.right
			elif xor >> i & 1:
				pos = pos.right
			else:
				pos = pos.left
		if pos:
			res = max(res, pos.max)
		return res

def solveequation(edge, ans, n, m):
	x = [0] * m
	used = [False] * n
	for v in range(n):
		if used[v]:
			continue
		y = dfs(v)
		if y != 0:
			return False
	return x

	def dfs(v):
		used[v] = True
		r = ans[v]
		for (to, dire, id) in edge[v]:
			if used[to]:
				continue
			y = dfs(to)
			if dire == -1:
				x[id] = y
			else:
				x[id] = -y
			r += y
		return r

class Matrix:
	mod = 10 ** 9 + 7

	def set_mod(m):
		Matrix.mod = m

	def __init__(self, L):
		self.row = len(L)
		self.column = len(L[0])
		self._matrix = L
		for i in range(self.row):
			for j in range(self.column):
				self._matrix[i][j] %= Matrix.mod

	def __getitem__(self, item):
		if type(item) == int:
			raise IndexError('you must specific row and column')
		elif len(item) != 2:
			raise IndexError('you must specific row and column')
		(i, j) = item
		return self._matrix[i][j]

	def __setitem__(self, item, val):
		if type(item) == int:
			raise IndexError('you must specific row and column')
		elif len(item) != 2:
			raise IndexError('you must specific row and column')
		(i, j) = item
		self._matrix[i][j] = val

	def __add__(self, other):
		if (self.row, self.column) != (other.row, other.column):
			raise SizeError('sizes of matrixes are different')
		res = [[0 for j in range(self.column)] for i in range(self.row)]
		for i in range(self.row):
			for j in range(self.column):
				res[i][j] = self._matrix[i][j] + other._matrix[i][j]
				res[i][j] %= Matrix.mod
		return Matrix(res)

	def __sub__(self, other):
		if (self.row, self.column) != (other.row, other.column):
			raise SizeError('sizes of matrixes are different')
		res = [[0 for j in range(self.column)] for i in range(self.row)]
		for i in range(self.row):
			for j in range(self.column):
				res[i][j] = self._matrix[i][j] - other._matrix[i][j]
				res[i][j] %= Matrix.mod
		return Matrix(res)

	def __mul__(self, other):
		if type(other) != int:
			if self.column != other.row:
				raise SizeError('sizes of matrixes are different')
			res = [[0 for j in range(other.column)] for i in range(self.row)]
			for i in range(self.row):
				for j in range(other.column):
					temp = 0
					for k in range(self.column):
						temp += self._matrix[i][k] * other._matrix[k][j]
					res[i][j] = temp % Matrix.mod
			return Matrix(res)
		else:
			n = other
			res = [[n * self._matrix[i][j] % Matrix.mod for j in range(self.column)] for i in range(self.row)]
			return Matrix(res)

	def __pow__(self, m):
		if self.column != self.row:
			raise MatrixPowError('the size of row must be the same as that of column')
		n = self.row
		res = Matrix([[int(i == j) for i in range(n)] for j in range(n)])
		while m:
			if m % 2 == 1:
				res = res * self
			self = self * self
			m //= 2
		return res

	def __str__(self):
		res = []
		for i in range(self.row):
			for j in range(self.column):
				res.append(str(self._matrix[i][j]))
				res.append(' ')
			res.append('\n')
		res = res[:len(res) - 1]
		return ''.join(res)

class SegmentTree:

	def __init__(self, init_val, segfunc, ide_ele):
		n = len(init_val)
		self.segfunc = segfunc
		self.ide_ele = ide_ele
		self.num = 1 << (n - 1).bit_length()
		self.tree = [ide_ele] * 2 * self.num
		for i in range(n):
			self.tree[self.num + i] = init_val[i]
		for i in range(self.num - 1, 0, -1):
			self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

	def update(self, k, x):
		k += self.num
		self.tree[k] = x
		while k > 1:
			self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
			k >>= 1

	def query(self, l, r):
		res = self.ide_ele
		l += self.num
		r += self.num
		while l < r:
			if l & 1:
				res = self.segfunc(res, self.tree[l])
				l += 1
			if r & 1:
				res = self.segfunc(res, self.tree[r - 1])
			l >>= 1
			r >>= 1
		return res

	def bisect_l(self, l, r, x):
		l += self.num
		r += self.num
		Lmin = -1
		Rmin = -1
		while l < r:
			if l & 1:
				if self.tree[l] <= x and Lmin == -1:
					Lmin = l
				l += 1
			if r & 1:
				if self.tree[r - 1] <= x:
					Rmin = r - 1
			l >>= 1
			r >>= 1
		if Lmin != -1:
			pos = Lmin
			while pos < self.num:
				if self.tree[2 * pos] <= x:
					pos = 2 * pos
				else:
					pos = 2 * pos + 1
			return pos - self.num
		elif Rmin != -1:
			pos = Rmin
			while pos < self.num:
				if self.tree[2 * pos] <= x:
					pos = 2 * pos
				else:
					pos = 2 * pos + 1
			return pos - self.num
		else:
			return -1
import sys, random, bisect
from collections import deque, defaultdict
from heapq import heapify, heappop, heappush
from itertools import permutations
from math import log, gcd
input = lambda : sys.stdin.readline().rstrip()
mi = lambda : map(int, input().split())
li = lambda : list(mi())
for _ in range(int(input())):
	ang = int(input())
	mini = (2 * ang - 1) // (180 - ang) + 1
	q = ang // gcd(180, ang)
	k = q * ((mini - 1) // q + 1)
	n = 180 * k // ang
	print(n)


n = int(input())
lst = list()
for i in range(n):
	lst.append(int(input()))
for ang in lst:
	n = 3
	while True:
		MAX = (n - 2) * 180 / n
		MIN = 180 / n
		if ang >= MIN and ang <= MAX and (divmod(ang, MIN)[1] == 0):
			print(n)
			break
		n += 1


import sys

def main():
	n = 0
	for line in sys.stdin:
		if not n:
			n = int(line.strip())
		else:
			degree = int(line.strip())
			there = 0
			for ngon in range(3, 998244353 + 1):
				if degree % (180 / ngon) == 0 and degree / (180.0 / ngon) <= ngon - 2:
					print(ngon)
					there = 1
					break
			if not there:
				print(-1)
			there = 0
main()


import math
n = int(input())
q = list(range(n))
l = 360
for i in range(0, n):
	ang = int(input())
	q1 = pow(ang, 1 / 2)
	if ang == 90:
		q[i] = 4
	elif ang == 120:
		q[i] = 6
	elif ang == 135:
		q[i] = 8
	elif ang == 144:
		q[i] = 10
	elif ang == 150:
		q[i] = 12
	elif ang == 160:
		q[i] = 18
	elif ang == 162:
		q[i] = 20
	elif ang == 165:
		q[i] = 24
	elif ang == 168:
		q[i] = 30
	elif ang == 170:
		q[i] = 36
	elif ang == 171:
		q[i] = 40
	else:
		for j in range(0, ang):
			if math.ceil(ang * 2 / (j + 1)) == math.floor(ang * 2 / (j + 1)):
				t = 360 / (ang * 2 / (j + 1))
				if math.ceil(t) == math.floor(t):
					if math.ceil(360 / t) == math.floor(360 / t):
						if l > t:
							l = t
		if ang > 173:
			l = l * 2
		q[i] = l
		l = 360
for i in range(0, n):
	print(int(q[i]))


t = int(input())
for i in range(t):
	x = int(input())
	for n in range(3, 361):
		if 180 * (n - 2) % n != 0:
			continue
		lim = 180 * (n - 2) // n
		if 180 % n == 0:
			step = 180 // n
		else:
			step = lim
		if lim >= x and x % step == 0:
			print(n)
			break


import math

class Solve(object):

	def solve(self, T):
		for i in range(T):
			n = int(input())
			gcd = math.gcd(n, 180)
			ans = 180 // gcd
			if ans - n // gcd <= 1:
				ans *= 2
			print(ans)
T = int(input())
s = Solve()
s.solve(T)


T = int(input())

def check(t):
	if t == 179:
		return 360
	for n in range(3, 181):
		if t * n % 180 == 0 and (n - 2) * 180 / n >= t:
			return n
	return -1
for _ in range(T):
	t = int(input())
	print(check(t))


T = int(input())
answer = []
for query in range(T):
	angle = int(input())
	n = 3
	ans = -1
	while n <= 998244353:
		if 2 * n * angle / 360 % 1 == 0 and 2 * n * angle / 360 < n - 1:
			ans = n
			break
		n += 1
	answer.append(str(ans))
print('\n'.join(answer))


for _ in range(int(input())):
	n = int(input())
	flag = 0
	for i in range(3, 1001):
		a = 180 * (i - 2) / i
		b = a / (i - 2)
		for j in range(1, i - 1):
			if b * j == n:
				print(i)
				flag = 1
				break
		if flag == 1:
			break
	if flag == 0:
		print(-1)


import math
for _ in [0] * int(input()):
	a = int(input())
	d = math.gcd(a, 180)
	print(-180 // d * (-2 * d // (180 - a)))


def func(a, b):
	mini = min(a, b)
	maxi = max(a, b)
	while maxi % mini != 0:
		(maxi, mini) = (mini, maxi % mini)
	return (a // mini, b // mini)

def main():
	count = int(input())
	for x in range(count):
		ang = int(input())
		(a, b) = func(2 * ang, 360)
		if a > b - 2:
			print(b * 2)
		elif b == 1:
			print(3)
		elif b == 2:
			print(4)
		else:
			print(b)
main()


import math
t = int(input())
for _ in range(t):
	a = int(input())
	p = a // math.gcd(180, a)
	q = 180 // math.gcd(180, a)
	if p == q - 1:
		print(2 * q)
	else:
		print(q)


def gcd(a, b):
	if a > b:
		return gcd(b, a)
	if a == 0:
		return b
	if b == a:
		return b
	return gcd(b - a, a)
n = int(input())
for i in range(n):
	cur = int(input())
	temp = 180 / gcd(cur, 180)
	tot = (temp - 2) * 180 / temp
	if cur <= tot:
		print(int(temp))
	else:
		print(int(temp * 2))


import sys
from math import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10 ** 5)
T = int(input())
for i in range(T):
	ang = int(input())
	g = gcd(ang, 180)
	gg = 180 // g
	a = ang // g
	if gg - a == 1:
		print(gg * 2)
	else:
		print(gg)


import sys
import math
t = int(input())
lisa = []
maxa = -1000000000.0
for i in range(t):
	n = int(input())
	flag = False
	for i in range(3, 998244354):
		if math.ceil(n % (180 / i)) == 0:
			if int((i - 2) * (180 / i)) >= n:
				print(i)
				flag = True
				break
		if flag:
			break


from math import gcd
t = int(input())
for i in range(t):
	ang = int(input())
	(ang, zn) = (ang // gcd(180, ang), 180 // gcd(180, ang))
	if zn - ang == 1:
		print(2 * zn)
	else:
		print(zn)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	pehle = [-1] * 181
	for i in range(3, 361):
		if 360 % i == 0:
			intangatmid = 360 // i
			if pehle[180 - intangatmid] == -1:
				pehle[180 - intangatmid] = i
			k = intangatmid
			while intangatmid + 2 * k <= 360:
				if intangatmid % 2 == 0 and pehle[intangatmid // 2] == -1:
					pehle[intangatmid // 2] = i
				intangatmid += k
	tc = ri()
	for _ in range(tc):
		n = ri()
		print(pehle[n])
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


t = int(input())
for i in range(t):
	a = int(input())
	if a == 180:
		print(-1)
		break
	for j in range(3, 181):
		if a * j % 180 == 0:
			if j - a * j // 180 == 1:
				j *= 2
			print(j)
			break


def GCD(a, b):
	if min(a, b) == 0:
		return max(a, b)
	else:
		return GCD(max(a, b) % min(a, b), min(a, b))
for i in range(int(input())):
	t = int(input())
	if t <= 60:
		print(180 // GCD(t, 180))
	else:
		a = 180 - t
		n = 180 // GCD(t, 180)
		if a * n / 180 < 2:
			n = 2 * n
		print(n)


import math

def C():
	T = int(input())
	for i in range(T):
		angle = int(input())
		d = math.gcd(180, angle)
		if angle + d >= 180:
			print(2 * 180 // d)
			continue
		print(180 // d)
C()


from collections import deque, Counter, OrderedDict
from heapq import nsmallest, nlargest

def binNumber(n, size):
	return bin(n)[2:].zfill(size)

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def iar():
	return list(map(int, input().split()))

def ini():
	return int(input())

def isp():
	return map(int, input().split())

def sti():
	return str(input())
t = ini()
for _ in range(t):
	ang = ini()
	i = 0
	if ang >= 90:
		ang = 180 - ang
		i = 2
	else:
		i = 1
	ang *= 2
	while True:
		if ang % i == 0:
			x = ang // i
			if i > ang:
				print(-1)
				break
			if 360 % x == 0:
				print(360 // x)
				break
		i += 1


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
T = int(input())
for i in range(T):
	ang = int(input())
	g = int(gcd(180, ang))
	k = ang / g
	n = 180 / g
	if k + 1 == n:
		n *= 2
	print(int(n))


from fractions import Fraction
n = int(input())
for _ in range(n):
	angle = int(input())
	f = Fraction(180, angle)
	if f.denominator <= f.numerator - 2:
		print(f.numerator)
	else:
		print(2 * f.numerator)


import os
import sys
import math
import collections
import cmath

def mp():
	return map(int, input().split())

def inp():
	return input()

def gcd(a, b):
	if a % b == 0:
		return b
	else:
		return gcd(b, a % b)
n = int(inp())
for x in range(n):
	a = int(inp())
	b = 180 // gcd(a, 180)
	if a == 180:
		print(-1)
		continue
	if abs(a // (180 // b) - b) == 1:
		print(b * 2)
	else:
		print(b)


max_N = 360
all_thetas = [-1] * 180
for n in range(3, max_N + 1):
	theta = 180 / n
	for x in range(1, n - 1):
		theta_ = theta * x
		if theta_ - int(theta_) == 0.0:
			if all_thetas[int(theta_)] == -1:
				all_thetas[int(theta_)] = n
t = int(input())
for _ in range(t):
	print(all_thetas[int(input())])


t = int(input())
s = [1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 18, 20, 24, 30, 36, 40, 45, 60, 72, 90, 120, 180]
for j in range(t):
	n = int(input())
	i = 1
	while i < 100:
		x = s[-i] / 2
		if n % x == 0.0 and n <= 180 - s[-i]:
			print(360 // s[-i])
			break
		else:
			i += 1


import sys
from array import array
import typing as Tp

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def main():
	t = int(input())
	for ang in (int(input()) for _ in range(t)):
		for n in range(3, 1000):
			if ang * n % 180 == 0 and 1 <= ang * n // 180 <= n - 2:
				print(n)
				break
		else:
			print(-1)
main()