#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
using namespace std;
const int N = 100003, M = 1003, inf = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-5;
typedef pair<int, int> PIR;
typedef long long ll;
const char space = ' ';
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
double a = n * 6 % 360, b = n / 2.0;
double res = a - b;
if (res < 0)
res = -res;
if (res > 180)
res = 360 - res;
res += eps;
printf("%.0lf\n", res);
}
return 0;
}