Let's denote correct match equation (we will denote it as CME) an equation $a + b = c$ there all integers $a$, $b$ and $c$ are greater than zero.

For example, equations $2 + 2 = 4$ (||+||=||||) and $1 + 2 = 3$ (|+||=|||) are CME but equations $1 + 2 = 4$ (|+||=||||), $2 + 2 = 3$ (||+||=|||), and $0 + 1 = 1$ (+|=|) are not.

Now, you have $n$ matches. You want to assemble a CME using all your matches. Unfortunately, it is possible that you can't assemble the CME using all matches. But you can buy some extra matches and then assemble CME!

For example, if $n = 2$, you can buy two matches and assemble |+|=||, and if $n = 5$ you can buy one match and assemble ||+|=|||.  [Image] 

Calculate the minimum number of matches which you have to buy for assembling CME.

Note, that you have to answer $q$ independent queries.


-----Input-----

The first line contains one integer $q$ ($1 \le q \le 100$) — the number of queries.

The only line of each query contains one integer $n$ ($2 \le n \le 10^9$) — the number of matches.


-----Output-----

For each test case print one integer in single line — the minimum number of matches which you have to buy for assembling CME. 


-----Example-----
Input
4
2
5
8
11

Output
2
1
0
1



-----Note-----

The first and second queries are explained in the statement.

In the third query, you can assemble $1 + 3 = 4$ (|+|||=||||) without buying matches.

In the fourth query, buy one match and assemble $2 + 4 = 6$ (||+||||=||||||).

Difficulty: EASY
Tags: Mathematics

Starter code:

Solutions:
x = int(input())
j = []
for i in range(x):
	n = int(input())
	if n < 4:
		if n == 2:
			j.append('2')
		if n == 1:
			j.append('3')
		if n == 3:
			j.append('1')
	elif n % 2 == 0:
		j.append('0')
	else:
		j.append('1')
for i in range(len(j)):
	print(j[i])


for _ in range(int(input())):
	n = int(input())
	if n % 2 == 0 and n > 2:
		print(0)
	elif n == 2:
		print(2)
	elif n % 2 != 0:
		print(1)


n = int(input())
for _ in range(n):
	a = int(input())
	if a == 2:
		print(2)
		continue
	if a % 2 == 0:
		print(0)
	else:
		print(1)


z = []
for x in range(int(input())):
	z.append(int(input()))
count = 0
for x in z:
	y = 0
	if x < 4:
		y = 4 - x
		print(y)
	else:
		for f in range(1000):
			if x % 2 == 0:
				print(count)
				count = 0
				break
			else:
				x = x + 1
				count = count + 1


t = int(input())
p = 0
for i in range(t):
	n = int(input())
	if n == 2:
		print(2)
	elif n % 2 == 0:
		print(0)
	else:
		print(1)


a = int(input())
g = []
for i in range(0, a):
	d = int(input())
	if d < 4:
		f = 4 - d
		g.append(str(f))
	elif d % 2 == 1:
		g.append('1')
	else:
		g.append('0')
print('\n'.join(g))


q = int(input())
for i in range(q):
	n = int(input())
	if n == 2:
		print(2)
	elif n % 2 == 1:
		print(1)
	else:
		print(0)


n = int(input())
m = []
for i in range(n):
	b = int(input())
	if b == 1:
		m.append(3)
	elif b == 2:
		m.append(2)
	else:
		m.append(b % 2)
print(*m, sep='\n')


n = int(input())
arr = []
for i in range(n):
	x = int(input())
	arr.append(x)

def KUS(n):
	if n % 2 == 0:
		if n >= 4:
			print(0)
		else:
			print(2)
	else:
		print(1)
for i in range(n):
	KUS(arr[i])


n = int(input())
b = []
for i in range(n):
	a = int(input())
	if a > 2 and a % 2 == 0:
		b.append(0)
	elif a < 4:
		b.append(4 - a)
	else:
		b.append(1)
for i in b:
	print(i)


n = int(input())
for i in range(n):
	x = int(input())
	if x == 2:
		print(2)
		continue
	if x % 2 != 0:
		print(1)
	else:
		print(0)


q = int(input())
ans = []
for i in range(q):
	a = int(input())
	if a >= 4:
		if a % 2 == 0:
			ans.append(0)
		else:
			ans.append(1)
	else:
		ans.append(4 - a)
print(*ans, sep='\n')


k = list()
m = list()
for _ in range(int(input())):
	m.append(int(input()))
for el in m:
	if el == 0:
		k.append(4)
	elif el == 1:
		k.append(3)
	elif el == 2:
		k.append(2)
	elif el % 2 == 0:
		k.append(0)
	else:
		k.append(1)
print(*k, sep='\n')


q = int(input())
for i in range(q):
	n = int(input())
	if n % 2 == 0:
		if n >= 4:
			print(0)
		elif n == 2:
			print(2)
		elif n == 0:
			print(4)
	elif n >= 3:
		print(1)
	elif n == 1:
		print(3)


q = int(input())
for i in range(q):
	n = int(input())
	a = n // 2
	o = 0
	if n % 2 != 0:
		a += 1
		o += 1
	w = n - a
	b = w // 2
	c = w - b
	if n < 4:
		o = 4 - n
	print(o)


a = int(input())
for i in range(a):
	b = int(input())
	if b % 2 == 0 and b >= 4:
		print(0)
	elif b < 4:
		print(4 - b)
	elif b % 2 != 0:
		c = b + 1
		print(c - b)


t = int(input())
ls = []
for i in range(t):
	n = int(input())
	ls.append(n)
for i in range(t):
	if ls[i] == 2:
		print(2)
	elif ls[i] % 2 == 0:
		print(0)
	else:
		print(1)


for x in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
	else:
		print(n % 2)


q = int(input())
while q != 0:
	q -= 1
	n = int(input())
	if n == 1:
		print('3')
	elif n == 2:
		print('2')
	elif n % 2 == 0:
		print('0')
	else:
		print('1')


for i in range(int(input())):
	n = int(input())
	if n > 2:
		print(n % 2)
	else:
		print(4 - n)


n = int(input())
for i in range(n):
	k = int(input())
	if k == 2:
		print(2)
	elif k == 3:
		print(1)
	elif k % 2 == 0:
		print(0)
	else:
		print(1)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
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')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]
for _ in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
	else:
		have = n // 2
		n -= ceil(n // 2)
		print(n - have)


n = int(input())
for i in range(n):
	m = int(input())
	if m % 2 == 0:
		if m == 2:
			print(2)
		else:
			print(0)
	else:
		print(1)


q = int(input())
for num in range(q):
	n = int(input())
	mone = ((n - 1) // 2 + 1) * 2 - n
	if n == 2:
		mone = 2
	if n == 1:
		mone = 3
	print(mone)


q = int(input())
res = []
for i in range(q):
	num = input()
	if num == '2':
		res.append(2)
	elif int(num[len(num) - 1]) % 2 == 0:
		res.append(0)
	else:
		res.append(1)
print(*res, sep='\n')


T = int(input())
for i in range(T):
	n = int(input())
	if n == 2:
		print(2)
	else:
		value = n % 2
		if value == 0:
			print(0)
		else:
			print(value)


def solve(n):
	if n == 2:
		return 2
	return n % 2

def main():
	nums = [print(solve(int(input()))) for _ in range(int(input()))]
main()


import math
q = int(input())
myList = []
for i in range(q):
	n = int(input())
	if n == 2:
		n = 3
		myList.append(math.ceil(n / 2) * 2 - n + 1)
	elif n == 1:
		n = 3
		myList.append(math.ceil(n / 2) * 2 - 1 - n)
	else:
		myList.append(math.ceil(n / 2) * 2 - n)
print(*myList, sep='\n')


m = int(input())
ans = []
for i in range(m):
	n = int(input())
	an = None
	if n < 4:
		an = 4 - n
	elif n % 2 != 0:
		an = 1
	else:
		an = 0
	ans.append(an)
for i in ans:
	print(i)


zaprosov = int(input())
for i in range(zaprosov):
	spichek = int(input())
	if spichek < 4:
		print(4 - spichek)
	else:
		if spichek % 2 == 0:
			print('0')
		if spichek % 2 == 1:
			print('1')


hm = int(input())
for i in range(hm):
	inp = int(input())
	if inp == 2:
		print(2)
	elif inp % 2 == 1:
		print(1)
	else:
		print(0)


q = int(input())
for i in range(q):
	n = int(input())
	h = 0
	if n % 2 != 0:
		n += 1
		h += 1
	a = 0
	b = 0
	while n // 2 != a + b:
		a = n // 2 // 2
		b = n // 2 - a
		if n // 2 != a + b:
			h += 1
			n += 1
			if n % 2 != 0:
				h += 1
				n += 1
		if a == 0 or b == 0:
			n += 1
			h += 1
			if n % 2 != 0:
				h += 1
				n += 1
	print(h)


otvet = []
kus = []
r = input()
for i in range(int(r)):
	t = input()
	kus.append(int(t))
	otvet.append(0)
for y in range(int(r)):
	if kus[y] % 2 == 0 and kus[y] > 2:
		otvet[y] = 0
	elif kus[y] > 2 and kus[y] % 2 == 1:
		otvet[y] = 1
	elif kus[y] == 2:
		otvet[y] = 2
	elif kus[y] == 1:
		otvet[y] = 3
	else:
		pass
for u in range(int(r)):
	print(otvet[u])


n = int(input())
for i in range(n):
	k = int(input())
	ans = max(4, k + k % 2)
	print(ans - k)


q = int(input())
a = []
for i in range(q):
	x = int(input())
	a.append(x)
for i in range(q):
	if a[i] < 4:
		print(4 - a[i])
	elif a[i] % 2 == 0:
		print(0)
	elif a[i] % 2 == 1:
		print(1)


def dokup(k):
	t = 0
	if k % 2 != 0:
		k += 1
		t += 1
	return t
n = int(input())
a = []
for i in range(n):
	a.append(int(input()))
	if a[i] <= 4:
		print(4 - a[i])
	else:
		print(dokup(a[i]))


a = int(input())
for _ in range(a):
	n = int(input())
	if n == 1:
		print('3')
	elif n == 2:
		print('2')
	elif n % 2 == 0:
		print('0')
	elif n % 2 != 0:
		print('1')


q = int(input())
n = ''
for i in range(q):
	n = n + ' ' + input()
c = n.split()
for j in c:
	n = int(j)
	if n != 2:
		if n % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		print(2)


q = int(input())
n = []
r = []
for i in range(0, q):
	n.append(int(input()))
	if n[i] < 4:
		r.append(4 - n[i])
	elif n[i] % 2 != 0:
		r.append(1)
	else:
		r.append(0)
for i in range(0, q):
	print(r[i])


for _ in range(int(input())):
	numb = int(input())
	if numb <= 2:
		print(2)
	elif numb % 2 == 0:
		print(0)
	else:
		print(1)


q = int(input())
for i in range(q):
	s = int(input())
	if s == 1:
		print(3)
	elif s == 2:
		print(2)
	elif s % 2 == 0:
		print(0)
	else:
		print(1)


I = input
q = int(I())
while q > 0:
	n = int(I())
	print(max(4 - n, n % 2))
	q -= 1


q = int(input())
s = []
g = 0
for i in range(q):
	a = int(input())
	s.append(a)
for j in range(len(s)):
	g = 0
	while s[j] % 2 != 0:
		s[j] += 1
		g += 1
	if s[j] == 2:
		g = 2
	print(g, sep='')


nb_input = int(input())
for o in range(nb_input):
	i = int(input())
	if i == 1:
		print(3)
	elif i % 2 != 0:
		print(1)
	elif i == 2:
		print(2)
	else:
		print(0)


def kus(a):
	if a == 2:
		return 2
	elif a % 2 == 0:
		return 0
	elif a % 2 == 1:
		return 1
q = int(input())
for i in range(q):
	s = int(input())
	print(kus(s))


import sys as _sys
_MIN_MATCHES_N = 4

def main():
	q = int(input())
	for i_q in range(q):
		(n,) = _read_ints()
		result = how_many_matches_to_buy(current_matches_n=n)
		print(result)

def _read_line():
	result = _sys.stdin.readline()
	assert result[-1] == '\n'
	return result[:-1]

def _read_ints():
	return map(int, _read_line().split(' '))

def how_many_matches_to_buy(current_matches_n):
	if current_matches_n < _MIN_MATCHES_N:
		result = _MIN_MATCHES_N - current_matches_n
	else:
		result = 1 if current_matches_n % 2 != 0 else 0
	return result
main()


n = int(input())
for _ in range(n):
	m = int(input())
	if m == 2:
		print(2)
	elif m % 2 == 0:
		print(0)
	else:
		print(1)


q = int(input())

def how_to_buy(n):
	if n < 4:
		return 4 - n
	if n % 2 != 0:
		return 1
	else:
		return 0
for _ in range(q):
	n = int(input())
	print(how_to_buy(n))


q = int(input())
A = []
for i in range(q):
	A.append(int(input()))

def kus(n):
	if n % 2 == 0 and n // 2 != 1:
		return 0
	if n < 4:
		return 4 - n
	return n % 2

def answers(A):
	result = []
	for i in A:
		result.append(kus(i))
	return result
for i in answers(A):
	print(i)


t = int(input())
for case in range(t):
	n = int(input())
	if n == 2:
		answer = 2
	elif n % 2 == 0:
		answer = 0
	elif n == 1:
		answer = 3
	else:
		answer = 1
	print(answer)


for _ in range(int(input())):
	n = int(input())
	print(2 if n == 2 else n & 1)


for i in range(int(input())):
	c = int(input())
	if c == 2:
		print(2)
	elif c % 2 == 1:
		print(1)
	else:
		print(0)


q = int(input())
for _ in range(q):
	n = int(input())
	print(2 if n == 2 else n % 2)


q = int(input())
for i in range(q):
	a = int(input())
	if a < 4:
		b = 4 - a
	elif a % 2 == 1:
		b = 1
	else:
		b = 0
	print(b)


n = int(input())
spicok = []
for i in range(0, n):
	a = int(input())
	spicok += [a]
for i in range(0, n):
	if int(spicok[i]) < 4:
		print(4 - int(spicok[i]))
	if int(spicok[i]) == 4:
		print(0)
	if int(spicok[i]) > 4:
		print((int(spicok[i]) - 4) % 2)


count = int(input())
for i in range(count):
	num = int(input())
	if num == 2:
		print(2, end=' ')
		continue
	if num % 2 == 1:
		print(1, end=' ')
		continue
	if num % 2 == 0:
		print(0, end=' ')
		continue


q = int(input())
while q > 0:
	n = int(input())
	if n == 2:
		print(2)
	if n != 2:
		if n % 2 == 0:
			print(0)
		if n % 2 > 0:
			print(n % 2)
	q = q - 1


for t in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
	else:
		print(1 if n % 2 else 0)


t = int(input())
for qwe in range(t):
	n = int(input())
	if n < 4:
		print(4 - n)
	elif n % 2 == 0:
		print(0)
	else:
		print(1)


a = int(input())
c = []
for x in range(a):
	b = input()
	c.append(b)
for x in range(a):
	if int(c[x]) == 2:
		print('2')
	elif int(c[x]) % 2 == 0:
		print('0')
	else:
		print('1')


z = []
for x in range(int(input())):
	z.append(int(input()))
for x in z:
	if x < 4:
		print(4 - x)
	else:
		print(x % 2)


for i in range(int(input())):
	a = int(input())
	if a == 0:
		print(4)
	elif a == 1:
		print(3)
	elif a == 2:
		print(2)
	elif a % 2 == 0:
		print(0)
	elif a % 2 == 1:
		print(1)


for i in range(int(input())):
	c = int(input())
	k = 0
	if c % 2 == 1:
		k += 1
	while (c + k) // 2 < 2:
		k += 1
	print(k)


for i in range(int(input())):
	n = int(input())
	a = n % 3
	if n % 2 == 0 and n > 3:
		print(0)
	elif n > 3:
		print(1)
	else:
		if n == 1:
			print(3)
		if n == 2:
			print(2)
		if n == 3:
			print(1)


n = int(input())
s = []
for i in range(n):
	a = int(input())
	if a < 4:
		s = s + [4 - a]
	elif a % 2 == 1:
		s = s + [1]
	else:
		s = s + [0]
for i in range(n):
	print(s[i])


import math

def kus(num):
	if num % 2 == 0 and num != 2:
		return 0
	elif num == 2:
		return 2
	else:
		return math.ceil(num / 2.0) * 2 - num
amount = int(input())
lst = []
for _ in range(amount):
	lst.append(int(input()))
for num in lst:
	print(kus(num))


tc = int(input())
for t in range(tc):
	q = int(input())
	if q > 2 and q % 2 == 0:
		print(0)
	elif q == 2:
		print(2)
	else:
		print(1)


q = int(input())
res = []
for _ in range(q):
	m = int(input())
	a = 0
	check = m % 2
	if m == 2:
		a = 2
	elif check:
		a = 1
	res.append(a)
for i in res:
	print(i)


m = int(input())
a = []
for i in range(m):
	n = int(input())
	if n <= 2:
		if n == 1:
			a.append(3)
		else:
			a.append(2)
		continue
	if n % 2 == 0:
		a.append(0)
	else:
		a.append(1)
for i in a:
	print(i)


n = int(input())
for n in range(n):
	m = int(input())
	if m < 4:
		print(4 - m)
	else:
		print(m % 2)


m = 0
n = int(input())
for i in range(n):
	k = int(input())
	m = 0
	if k == 2:
		m = 2
	elif k % 2 == 1:
		m = 1
	elif k % 2 == 0:
		m = 0
	print(m)


q = int(input())
l = []
for _ in range(q):
	n = int(input())
	l.append(4 - n if n < 4 else n % 2)
for _ in l:
	print(str(_))


q = int(input())
a = [] * q
for i in range(q):
	a.append(int(input()))
for i in range(q):
	if a[i] == 2:
		print(2)
	if a[i] % 2 == 0 and a[i] != 2:
		print(0)
	if a[i] % 2 == 1:
		print(1)


n = int(input())
for i in range(n):
	p = int(input())
	if p == 2:
		print(2)
	elif p % 2 != 0 or p % 2 == 0:
		red = p - 2 * (p // 2)
		print(red)


a = int(input())
for i in range(a):
	b = int(input())
	if b == 2:
		print(2)
	elif not b % 2:
		print(0)
	elif b % 2:
		print(1)


q = int(input())
for _ in range(q):
	n = int(input())
	if n < 4:
		print(4 - n)
	elif n % 2 == 1:
		print(1)
	else:
		print(0)


t = int(input())
for j in range(t):
	n = int(input())
	if n == 2:
		v = 2
	elif n % 2 == 0:
		v = 0
	else:
		v = 1
	print(v)


q = int(input())
ans = [0] * q
for i in range(q):
	n = int(input())
	while n / 2 != n // 2 or n <= 2:
		n += 1
		ans[i] += 1
for i in ans:
	print(i)


n = int(input())
for _ in range(n):
	have = int(input())
	if have < 4:
		print(4 - have)
		continue
	a = 1
	b = (have - 2) // 2
	c = b + 1
	need = have - (a + b + c)
	print(need)


def spich(a):
	if a < 4:
		print(4 - a)
	elif a % 2 == 0:
		print(0)
	else:
		print(1)
k = int(input())
x = []
for i in range(k):
	x.append(int(input()))
for i in range(k):
	spich(x[i])


n = int(input())
CASES = []
for i in range(n):
	y = int(input())
	CASES.append(y)
ANS = []
for el in CASES:
	if el == 0:
		res = 4
		ANS.append(str(res))
	elif el == 2:
		res = 2
		ANS.append(str(res))
	elif el % 2 == 0:
		res = 0
		ANS.append(str(res))
	elif el % 2 == 1:
		res = 1
		ANS.append(str(res))
for i in range(len(ANS)):
	print(ANS[i])


n = int(input())
array = []
for _ in range(n):
	array.append(int(input()))
for s in array:
	q = 0
	if s == 2:
		print(2)
	else:
		print(s % 2)


q = int(input())
nums = []
for _ in range(q):
	nums.append(int(input()))
for num in nums:
	if num < 4:
		print(4 - num)
	elif num % 2 == 0:
		print(0)
	else:
		print(1)


number_q = int(input())

def answer(n):
	if n == 2:
		print(2)
	elif n % 2 == 0:
		print(0)
	else:
		print(1)
for i in range(number_q):
	temp = int(input())
	answer(temp)


q = int(input())
a = []
for i in range(q):
	a.append(int(input()))
for j in range(q):
	if a[j] != 2:
		if a[j] % 2 != 0:
			print(1)
		else:
			print(0)
	else:
		print(2)


q = int(input())
for quests in range(q):
	new = int(input())
	if new >= 4:
		if new % 2 == 0:
			print(0)
		else:
			print(1)
	elif new == 2:
		print(2)
	elif new == 3:
		print(1)


tc = int(input())
A = []
for i in range(tc):
	A.append(int(input()))
for i in A:
	if i == 0:
		print(4 - 0)
	elif i == 1:
		print(3)
	elif i == 2:
		print(2)
	else:
		print(i % 2)


q = int(input())
for i in range(q):
	x = int(input())
	if x == 2:
		print(2)
	else:
		print(x % 2)


import math
n = int(input())
for i in range(n):
	c = int(input())
	if c % 4 == 0:
		print(0)
	else:
		ans = int(math.ceil(c / 2))
		if ans < 2:
			ans += 1
		print(ans * 2 - c)


for i in range(int(input())):
	n = int(input())
	if n < 4:
		print(4 - n)
	elif n % 2 == 0 and n >= 4:
		print(0)
	else:
		print(1)


n = int(input())
l = []
for i in range(n):
	m = int(input())
	if m >= 4:
		if m % 2 != 0:
			l.append(1)
		else:
			l.append(0)
	else:
		l.append(4 - m)
for i in l:
	print(i)


t = int(input())
for i in range(t):
	x = int(input())
	if x == 2:
		print('2')
	elif x % 2 == 1:
		print('1')
	else:
		print('0')


q = int(input())
result = str()
for x in range(q):
	n = int(input())
	if n == 2:
		result = f'{result}\n2'
		continue
	min_kus = n - n // 2 * 2
	result = f'{result}\n{min_kus}'
result = result.strip()
print(result)


n = int(input())
m = []
for i in range(n):
	c = int(input())
	i = 1
	x = 0
	while i == 1:
		if c % 2 == 0 and c // 2 - 1 != 0:
			m.append(x)
			i = 0
		else:
			c += 1
			x += 1
for i in range(len(m)):
	print(m[i])


q = int(input())
for i in range(q):
	n = int(input())
	x = n // 2
	if n == 2:
		print(2)
		continue
	print(n - x * 2)


no_of_queries = int(input(''))
no_of_matches = []
for query in range(0, no_of_queries):
	no_of_matches.append(int(input('')))
for number in no_of_matches:
	if number == 2:
		print(2)
	elif number % 2 == 1:
		print(1)
	else:
		print(0)


q = int(input())
for i in range(q):
	ch = int(input())
	if ch < 4:
		print(4 - ch)
	elif ch % 2 == 0:
		print(0)
	else:
		print((ch // 2 + 1) * 2 - ch)


n = int(input())
for i in range(n):
	r = int(input())
	if r == 0:
		print(4)
	elif r == 1:
		print(3)
	elif r == 2:
		print(2)
	elif r % 2 == 0:
		print(0)
	else:
		print(1)


t = int(input())
x = 0
for x in range(t):
	matches = int(input())
	sum = 0
	total = 0
	var1 = 0
	var2 = 0
	if matches == 2:
		print(2)
		continue
	if matches % 2 == 0:
		print(0)
		continue
	else:
		print(1)


n = int(input())
parms = [next(map(int, input().split())) for i in range(n)]
for i in parms:
	if i < 4:
		print(4 - i)
	elif (i - 1) % 2 == 0:
		print(1)
	else:
		print(0)


import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

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

def F():
	return float(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def main():
	n = I()
	ans = []
	for _ in range(n):
		a = I()
		if a <= 4:
			ans.append(4 - a)
		elif a % 2 == 0:
			ans.append(0)
		else:
			ans.append(1)
	for x in ans:
		print(x)
main()


q = int(input())
ans = []
for i in range(q):
	n = int(input())
	if n < 4:
		ans.append(4 - n)
	if n % 2 == 0 and n >= 4:
		ans.append(0)
	if n % 2 != 0 and n >= 4:
		ans.append(1)
for e in ans:
	print(e)


q = int(input())
a = []
for i in range(q):
	a.append(int(input()))
for i in range(len(a)):
	if a[i] == 2:
		print(2)
	elif a[i] % 2 == 0:
		print(0)
	elif a[i] % 2 != 0:
		print(1)


for x in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
	elif n % 2 == 0:
		print(0)
	else:
		print(int(n % 2))


q = int(input())
a = [0] * q
for i in range(q):
	n = int(input())
	if n == 2:
		a[i] = 2
	elif n % 2 == 0:
		a[i] = 0
	elif n % 2 != 0:
		a[i] = 1
for k in a:
	print(k)


import sys, math, 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())
n = I()
for i in range(n):
	s = I()
	if s == 2:
		print(s)
	else:
		print(s % 2)


q = int(input())
li = []
lo = []
for i in range(q):
	a = int(input())
	li.append(a)
for i in li:
	if i == 1:
		lo.append(3)
	elif i == 2:
		lo.append(2)
	elif i % 2 == 0:
		lo.append(0)
	else:
		lo.append(1)
for i in lo:
	print(i)


q = int(input())
for _ in range(q):
	i = int(input())
	if i < 4:
		print(str(4 - i))
	elif i % 2 == 0:
		print('0')
	else:
		print('1')


q = int(input())
nums = list(map(int, [int(input()) for i in range(q)]))
for num in nums:
	if num == 2:
		print(2)
	elif num % 2 == 1:
		print(1)
	else:
		print(0)


n = int(input())
li = []
for i in range(n):
	li.append(int(input()))
for match in li:
	if match == 2:
		print('2')
	else:
		print(match % 2)


s = int(input())
i = 0
a = []
while i != s:
	n = int(input())
	if n % 2 == 0 and n != 2:
		a += '0'
	else:
		x = 0
		while n % 2 != 0 or n == 2:
			n += 1
			x += 1
		a += str(x)
	i += 1
s -= 1
i = 0
while s != -1:
	print(a[i])
	s -= 1
	i += 1


q = int(input())
k = 0

def check_cme(n):
	global k
	k = 0
	if n > 2:
		if n % 2 != 0:
			k = 1
	else:
		k = 2
	return k
for i in range(0, q):
	x = int(input())
	print(check_cme(x))


q = int(input())
for i in range(q):
	if q >= 1 and q <= 100:
		n = int(input())
		if n >= 2 and n <= 10 ** 9:
			if n == 2:
				print(2)
			elif n % 2 != 0:
				print(1)
			else:
				print(0)
		else:
			break
	else:
		break


def match(num):
	if num == 2:
		print(2)
	elif num % 2 == 0:
		print(0)
	else:
		print(1)
n = int(input())
for i in range(n):
	match(int(input()))


q = int(input())
matches = []
matches_to_buy = []
for i in range(q):
	match = int(input())
	matches.append(match)
for match in matches:
	if match == 1:
		matches_to_buy.append(3)
	elif match == 2:
		matches_to_buy.append(2)
	elif match % 2 == 0:
		matches_to_buy.append(0)
	else:
		matches_to_buy.append(1)
for match in matches_to_buy:
	print(match)


case = int(input())
for i in range(case):
	matches = int(input())
	if matches == 2:
		print('2')
	elif matches % 2 == 0:
		print('0')
	else:
		print('1')


def task_1():
	n = int(input())
	for i in range(n):
		num = int(input())
		if num == 2:
			print(2)
			continue
		print(num % 2)

def task_2():
	n = int(input())
	for i in range(n):
		word_1 = str(input())
		word_2 = str(input())
		for ch1 in word_1:
			for ch2 in word_2:
				if ch1 == ch2:
					print('YES')
					break
		print('NO')
task_1()


from math import *
from sys import *
from heapq import *
from collections import defaultdict
import os, sys
from io import IOBase, BytesIO
M = 10 ** 9 + 7

def pow(a, b):
	res = 1
	while b > 0:
		if b & 1:
			res *= a
		a *= a
		b >>= 1
	return res

def powmod(a, b, m):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a *= a
		b >>= 1
	return res

def inv(a, m):
	return powmod(a, m - 2, m)

def alldivisors(n):
	list = []
	arr = []
	for i in range(1, int(sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				arr += [i]
			else:
				arr += [i]
				list.append(n // i)
	arr += list[::-1]
	return arr

def primefactorisation(n):
	potentional_p = 3
	itog_list = defaultdict(int)
	if n % 2 == 0:
		itog_list[2] = 0
	while n % 2 == 0:
		n = n // 2
		itog_list[2] += 1
	while n - 1:
		if potentional_p > n ** 0.5:
			itog_list[n] += 1
			return itog_list
		while n % potentional_p == 0:
			n = n // potentional_p
			itog_list[potentional_p] += 1
		potentional_p += 2
	return itog_list

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		if n < 4:
			print(4 - n)
		elif n & 1:
			print(1)
		else:
			print(0)
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.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')
main()


n = int(input())
arr = []
for i in range(n):
	arr.append(int(input()))
for i in arr:
	if i == 2:
		print(2)
		continue
	else:
		print(i % 2)


i = int(input())
count = 1
while count <= i:
	j = int(input())
	if j > 2:
		if j % 2 == 0:
			print(0)
		else:
			print(1)
	elif j == 1:
		print(3)
	elif j == 2:
		print(2)
	count += 1


num_input = int(input())
list_of_numbers = []
list_of_answers = []
for i in range(num_input):
	current_input = int(input())
	list_of_numbers.append(current_input)
for current_number in list_of_numbers:
	if current_number < 4:
		list_of_answers.append(4 - current_number)
	elif current_number % 2 == 0:
		list_of_answers.append(0)
	else:
		list_of_answers.append(1)
for current_number in list_of_answers:
	print(current_number)


n = int(input())
matches = list()
for i in range(0, n):
	matches.append(int(input()))
ans = list()
for i in range(0, n):
	if matches[i] == 2:
		ans.append(2)
	elif matches[i] % 2 == 0:
		ans.append(0)
	else:
		ans.append(1)
for i in range(0, n):
	print(ans[i], end='\n')


q = int(input())
d = []
for i in range(q):
	d.append(int(input()))
for i in range(q):
	n = d[i]
	if n < 4:
		print(4 - n)
	else:
		print(n % 2)


for a in range(int(input())):
	n = int(input())
	print(2 if n == 2 else n & 1)


n = int(input())
l = []
for i in range(n):
	l.append(int(input()))

def cme(a):
	if a == 1:
		return 3
	if a == 2:
		return 2
	if a == 3:
		return 1
	elif a % 2 == 0:
		return 0
	elif a % 2 != 0:
		return 1
for a in l:
	print(cme(a))


t = int(input())
while t:
	n = int(input())
	if n == 2:
		print('2')
	elif n % 2 == 0:
		print('0')
	elif n % 2 != 0:
		print('1')
	t -= 1


repetition = int(input())
for times in range(repetition):
	matches = int(input())
	if matches == 2:
		print('2')
	elif matches % 2 == 1:
		print('1')
	elif matches % 2 == 0:
		print('0')


n = int(input())
mas = []
for i in range(n):
	x = int(input())
	if x == 1:
		mas.append(3)
	elif x == 2:
		mas.append(2)
	else:
		mas.append(x % 2)
for i in range(n):
	print(mas[i])


q = int(input())
for i in range(q):
	n = int(input())
	if n < 3:
		print(4 - n)
		continue
	else:
		print(n % 2)


q = int(input())
requests = []
for i in range(q):
	requests.append(int(input()))
for i in range(q):
	if requests[i] < 4:
		print(4 - requests[i])
	elif requests[i] % 2 == 0:
		print(0)
	else:
		print(1)


from sys import stdin
input = stdin.readlines()
lines = [line.rstrip() for line in input]

def main():
	for t in range(int(lines[0])):
		n = int(lines[1:][t])
		print(2 if n == 2 else n & 1)
	pass
main()


def evengt(n):
	i = n
	while 1:
		if i % 2 == 0:
			return i
		i += 1
q = int(input())
n = []
for _ in range(q):
	n.append(int(input()))
for i in range(q):
	a = evengt(n[i])
	if a == 2:
		a = 4
	print(a - n[i])


q = int(input())
a = []
for i in range(q):
	a += [int(input())]
for i in range(q):
	if a[i] == 1:
		print(3)
	elif a[i] == 2:
		print(2)
	else:
		print(a[i] % 2)


def cme(n):
	if n % 2 == 1:
		return 1
	elif n == 2:
		return 2
	else:
		return 0
q = int(input())
for i in range(q):
	print(cme(int(input())))


n = int(input())
for x in range(n):
	k = int(input())
	if k == 2:
		print(2)
		continue
	if k == 1:
		print(3)
		continue
	if k % 2 == 0:
		print(0)
	else:
		print(1)


freq = int(input())
for i in range(freq):
	n = int(input())
	if n == 2:
		print('2')
	else:
		print(n & 1)


for i in range(int(input())):
	k = int(input())
	if k > 2:
		print((k + 1) // 2 - k // 2)
	else:
		print(4 - k)


a = int(input())
for i in range(a):
	n = int(input())
	if n == 2:
		print('2')
	else:
		print(n % 2)


for _ in range(int(input())):
	n = int(input())
	if n <= 3:
		print(4 - n)
	else:
		print(n % 2)


q = int(input())
i = 0
while i < q:
	n = int(input())
	if n >= 4:
		c = n // 2
		print(n - 2 * c)
	else:
		print(4 - n)
	i += 1


def f(n):
	if n == 2:
		return 2
	if n % 2 == 0:
		return 0
	return 1
for i in range(int(input())):
	print(f(int(input())))


import math
n = int(input())
for i in range(n):
	num = int(input())
	count = 0
	right = math.ceil(num / 2)
	left = num - right
	if left == right and left > 1:
		print(0)
		continue
	if left + 1 == right:
		print(1)
		continue
	if left + 1 == right + 1:
		print(2)


n = int(input())
L = []
for i in range(n):
	h = int(input())
	if h == 1:
		L.append(3)
	elif h == 2:
		L.append(2)
	elif h % 2 == 1:
		L.append(1)
	elif h % 2 == 0:
		L.append(0)
for i in range(len(L)):
	print(L[i])


q = int(input())
a = []
b = []
i = 0
j = 0
x = 0
for j in range(q):
	a.append(int(input()))
for i in range(q):
	if a[i] == 1:
		b.append(3)
	elif a[i] == 2:
		b.append(2)
	elif a[i] % 2 == 0:
		b.append(0)
	elif a[i] % 2 == 1:
		b.append(1)
print(*b, sep='\n')


def f(n):
	if n < 4:
		return 4 - n
	return n % 2
q = int(input())
inp = [int(input()) for _ in range(q)]
print(*map(f, inp), sep='\n')


t = int(input())
for _ in range(t):
	s = int(input())
	res = 0
	if s % 2 == 0 and s >= 4:
		pass
	elif s % 2 == 1 and s >= 4:
		res += s % 2
	else:
		res += 4 - s
	print(res)


x = int(input())
for i in range(x):
	a = int(input())
	if a <= 3:
		print(4 - a)
	else:
		print(a % 2)


n = int(input())
a = []
for i in range(n):
	x = int(input())
	if x % 2 == 0:
		if x != 2:
			a.append(0)
		else:
			a.append(2)
	else:
		a.append(1)
for i in range(n):
	print(a[i])


I = lambda : int(input())
for i in "'" * I():
	n = I()
	print(max(4 - n, n % 2))


t = int(input())
for test in range(t):
	n = int(input())
	if n < 4:
		print(4 - n)
	else:
		print(n % 2)


h = int(input())
for i in range(h):
	a = int(input())
	if a < 4:
		print(4 - a)
	elif a % 2 != 0:
		print(1)
	else:
		print(0)


t = int(input())
for _ in range(t):
	n = int(input())
	if n > 2:
		print(n % 2)
	else:
		print(2)


a = int(input())
i = 0
while i < a:
	b = int(input())
	if b % 2 == 1:
		print('1')
	elif b == 2:
		print('2')
	elif b % 2 == 0:
		print('0')
	i = i + 1


q = int(input())
i = 0
while i < q:
	n = int(input())
	buy = 0
	if n < 3:
		buy = 4 - n
		print(buy)
	elif n % 2 == 0:
		print(0)
	else:
		print(1)
	i += 1


for q in range(int(input())):
	n = int(input())
	print(max(n % 2, 4 - n))


q = int(input())
input_t = []
for i in range(q):
	input_t.append(int(input()))
for i in range(q):
	if input_t[i] == 2:
		print('2')
	elif input_t[i] % 2 == 1:
		print('1')
	else:
		print('0')


import math
for _ in range(int(input())):
	n = int(input())
	if n > 2:
		if n % 2 == 0:
			k = n // 2
			if k % 2 == 0:
				print('0')
			else:
				temp = math.ceil(k / 2)
				res = 2 * temp - (n - k) - 1
				print(res)
		else:
			temp = math.ceil(n / 2)
			if temp % 2 == 0:
				l = temp // 2
				res = 2 * l - (n - temp)
				print(res)
			else:
				l = math.ceil(temp / 2)
				res = 2 * l - (n - temp) - 1
				print(res)
	else:
		print('2')


number = int(input())
for i in range(number):
	a = int(input())
	if a == 1:
		print(1)
	elif a == 2:
		print(2)
	elif a % 2 == 0:
		print(0)
	else:
		print(1)


n = int(input())
a = list()
for i in range(n):
	a.append(int(input()))
for i in range(len(a)):
	if a[i] <= 4:
		print(4 - a[i])
	elif a[i] % 2 == 0:
		print(0)
	elif a[i] % 2 == 1:
		print(1)


q = int(input())
e = []
for i in range(q):
	a = int(input())
	e.append(a)
for i in range(q):
	if e[i] == 1:
		print(3)
	elif e[i] == 2:
		print(2)
	elif e[i] % 2 == 0:
		print(0)
	elif e[i] % 2 == 1:
		print(1)


q = int(input())
n = []
for x in range(q):
	n.append(int(input()))
for x in range(q):
	if n[x] == 2:
		print('2')
	elif n[x] % 2 == 0:
		print('0')
	elif n[x] % 2 == 1:
		print('1')


def cme(n):
	if n == 2:
		print(2)
		return
	if n % 2 == 0:
		print(0)
		return
	else:
		print(1)
n = int(input().strip(' '))
for i in range(n):
	cme(int(input().strip(' ')))


n = int(input())
for i in range(n):
	s = int(input())
	if s >= 4 and s % 2 == 0:
		print(0)
	if s >= 4 and s % 2 != 0:
		print(1)
	if s == 2:
		print(2)
	if s == 3:
		print(1)


def test():
	n = int(input())
	if n > 2 and n % 2 == 0:
		ans = 0
	elif n <= 2:
		ans = 4 - n
	else:
		ans = 1
	print(ans)

def main():
	q = int(input())
	for _ in range(q):
		test()
main()


import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
INF = 1 << 60
MOD = 10 ** 9 + 7
q = int(input())
for i in range(q):
	n = int(input())
	if n == 2:
		print(2)
	elif n % 2 == 0:
		print(0)
	else:
		print(1)


q = int(input())
for i in range(q):
	cnt = int(input())
	if cnt % 2 == 0 and cnt / 2 >= 2:
		print(0)
	else:
		print(abs(2 * (cnt // 2 + 1) - cnt))


n = int(input())
store = []
for i in range(n):
	m = int(input())
	if m == 2:
		store.append(2)
	elif m % 2 == 0:
		store.append(0)
	elif m % 2 != 0:
		store.append(1)
for i in store:
	print(i)


m = int(input())
while m > 0:
	m -= 1
	n = int(input())
	if n == 2:
		print(2)
	elif n % 2 == 0 and n > 2:
		print(0)
	else:
		print(1)


q = input()
target = 4
n = [None] * int(q)
for i in range(0, int(q)):
	n[i] = input()
for i in range(0, int(q)):
	target = 4
	if int(n[i]) < target:
		kurang = target - int(n[i])
		print(kurang)
	else:
		hasil = int(n[i]) % 2
		print(hasil)
	target += 2


q = int(input())
for i in range(q):
	l = int(input())
	if l == 2:
		print(2)
	elif l == 3:
		print(1)
	elif l >= 4:
		if l % 2 == 0:
			print(0)
		else:
			print(1)


import os
import sys
DEBUG = 'DEBUG' in os.environ

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

def read_int():
	return int(inp())

def read_ints():
	return [int(e) for e in inp().split()]

def dprint(*value, sep=' ', end='\n'):
	if DEBUG:
		print(*value, sep=sep, end=end)

def main():
	N = read_int()
	if N < 4:
		return 4 - N
	if N % 2 == 0:
		return 0
	else:
		return 1
for _ in range(read_int()):
	print(main())


n = int(input())
for _ in range(n):
	x = int(input())
	if x == 1:
		print(3)
	elif x == 2:
		print(2)
	elif x % 2 == 0:
		print(0)
	else:
		print(1)


def CME(n):
	if n == 1:
		return 3
	elif n == 2:
		return 2
	elif n % 2 == 0:
		return 0
	elif n % 2 != 0:
		return 1
t = int(input())
for i in range(t):
	a = int(input())
	ans = CME(a)
	print(ans)


i = int(input())
b = []
for j in range(i):
	b += [int(input())]
for z in b:
	if z < 4:
		print(4 - z)
	elif z % 2 == 0:
		print(0)
	elif z % 2 != 0:
		print(1)


n = int(input())
for _ in range(0, n):
	i = int(input())
	if i > 2:
		print(i % 2)
	elif i == 2:
		print(2)
	else:
		print(3)


t = int(input())
for _ in range(t):
	m = int(input())
	if m > 2:
		c = m // 2
		a_b = m - c
		if a_b != c:
			if m == c + a_b:
				print(1)
			else:
				print(2)
		else:
			print(0)
	else:
		print(2)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	a = math.ceil(n / 2)
	b = 1
	if a > 1:
		a = a - 1
	else:
		a = 1
	print(2 * (a + b) - n)


n = int(input())
for i in range(n):
	q = int(input())
	if q == 2:
		print(2)
	else:
		print(q % 2)


def get_ans(n):
	if n < 4:
		return 4 - n
	elif n % 2 == 1:
		return 1
	else:
		return 0
q = int(input())
outp = []
for i in range(q):
	outp.append(get_ans(int(input())))
for i in outp:
	print(i)


q = int(input())
array = []
for i in range(q):
	n = int(input())
	array.append(n)
for i in range(len(array)):
	if array[i] == 2:
		array[i] = 2
	if array[i] % 2 != 0:
		array[i] = 1
	if array[i] > 2 and array[i] % 2 == 0:
		array[i] = 0
for i in array:
	print(i)


i0 = int(input())
i1 = {}
for x in range(i0):
	i1[x] = int(input())
for x in range(len(i1)):
	if i1[x] % 2 == 0:
		if i1[x] / 2 == 1:
			print('2')
		else:
			print('0')
	else:
		print('1')


total = int(input())
b = []
i = total
while i > 0:
	i = i - 1
	b.append(int(input()))
while i < total:
	if b[i] == 2:
		print(2)
	else:
		print(b[i] % 2)
	i = i + 1


repeat = int(input())
while repeat > 0:
	n = int(input())
	if n == 1 or n == 2:
		print(2)
		repeat -= 1
	elif n % 2 == 0:
		print(0)
		repeat -= 1
	else:
		print(1)
		repeat -= 1


a = int(input())
for i in range(a):
	b = int(input())
	if b > 2:
		if b % 2 == 0:
			print('0')
		else:
			print(b % 2)
	elif b == 2:
		print('2')


n = int(input())
s = []
for i in range(n):
	l = int(input())
	if l == 2:
		s.append(2)
	elif l % 2 == 1:
		s.append(1)
	elif l % 2 == 0:
		s.append(0)
for i in range(len(s)):
	print(s[i])


def fun(arr):
	for i in range(0, len(arr)):
		if arr[i] == 2:
			print(2)
		elif arr[i] % 2 == 0:
			print(0)
		else:
			print(1)
t = int(input())
arr = []
for i in range(0, t):
	n = int(input())
	arr.append(n)
fun(arr)


n = int(input())
list = []
for i in range(1, n + 1):
	a = int(input())
	list.append(a)
for i in list:
	if i == 2:
		print('2')
	elif i % 2 == 0:
		print('0')
	else:
		print('1')


n = int(input())
if n >= 1 and n <= 100:
	for i in range(n):
		k = int(input())
		if k >= 2 and k <= pow(10, 9):
			if k == 2:
				count = 2
			elif k % 2 != 0:
				count = 1
			elif k % 2 == 0:
				count = 0
		print(count)


def respuesta(n):
	if n <= 4:
		return 4 - n
	if n % 2 == 0:
		return 0
	else:
		return 1
querys = int(input())
for i in range(0, querys):
	n = int(input())
	print(respuesta(n))


t = int(input())
while t:
	n = int(input())
	if n <= 4:
		print(4 - n)
	else:
		print(n % 2)
	t = t - 1


import sys
n = int(input())
for i in range(n):
	number = int(input())
	if number == 2:
		print('2')
	elif number % 2 == 0 and n > 2:
		print('0')
	else:
		print('1')


for _ in range(int(input())):
	curr = int(input())
	print([curr & 1, 2][curr == 2])


q = int(input())
for i in range(q):
	n = int(input())
	if n < 4:
		print(4 - n)
	elif n >= 4:
		print(n % 2)


q = int(input())
for i in range(q):
	a = int(input())
	if a == 2:
		print(2)
	else:
		print(int(a % 2 != 0))


q = int(input())
i = 0
mas = []
while i < q:
	n = int(input())
	mas.append(n)
	i += 1
i = 0
while i < q:
	n = mas[i]
	i += 1
	if n < 4:
		print(4 - n)
	elif n % 2 == 0:
		print(0)
	else:
		print(1)


q = int(input())
k = []
for i in range(q):
	b = int(input())
	k.append(0)
	if b % 2 != 0:
		k[i] = 1
	elif b == 2:
		k[i] = 2
	elif b % 2 == 0:
		k[i] = 0
for i in k:
	print(i)


t = int(input())
for x in range(t):
	i = int(input())
	if i == 0:
		print('4')
	elif i == 1:
		print('3')
	elif i == 2:
		print('2')
	elif i % 2 == 0:
		print('0')
	if i % 2 == 1:
		print('1')


n = int(input())
l = []
for i in range(n):
	l.append(int(input()))
for u in l:
	if u == 2:
		print(2)
	elif u % 2 == 1:
		print(1)
	else:
		print(0)


n = int(input())
for i in range(n):
	x = int(input())
	if x == 1:
		print(3)
	elif x == 2:
		print(2)
	if x > 2:
		if x % 2 != 0:
			z = x % 2
			print(z)
		else:
			print(0)


for _ in range(int(input())):
	count = int(input())
	if count > 2:
		print(count % 2)
	elif count == 2:
		print(2)
	elif count == 1:
		print(3)
	elif count == 0:
		print(4)


a = int(input())
for i in range(a):
	s = int(input())
	if s == 2:
		print(2)
	else:
		print(s % 2)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

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

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

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

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def main():
	t = I()
	rr = []
	for _ in range(t):
		n = I()
		if n <= 4:
			rr.append(4 - n)
		else:
			rr.append(n % 2)
	return JA(rr, '\n')
print(main())


def solve(n):
	if n < 4:
		return 4 - n
	if n % 2 is 0:
		return 0
	return 1
q = int(input())
res = [str(solve(int(input()))) for x in range(q)]
print('\n'.join(res))


q = int(input())
while q > 0:
	a = int(input())
	if a % 2 == 0 and a > 3:
		print(0)
	elif a < 3:
		print(4 - a)
	else:
		print(1)
	q = q - 1


q = int(input())
arr = []
for i in range(q):
	n = int(input())
	if n == 2:
		arr.append(2)
	elif n % 2 == 0:
		arr.append(0)
	else:
		arr.append(1)
for num in arr:
	print(num)


n = int(input())
for i in range(n):
	kol = int(input())
	koll = 1
	if kol != 2 and kol % 2 == 0:
		print(0)
		continue
	else:
		num = kol // 2
	koll += num + num + 1
	print(abs(koll - kol))


q = int(input())
for i in range(q):
	k = int(input())
	if k == 2:
		print(2)
	else:
		print(k % 2)


def check(a):
	if a < 4:
		return 4 - a
	if a % 2 == 0:
		return 0
	return 1
n = int(input())
for t in range(n):
	print(check(int(input())))


n = int(input())
a = []
for i in range(n):
	x = int(input())
	if x > 2 and x % 2 == 0:
		summ = x // 2
	elif x > 2:
		summ = x // 2 + 1
	else:
		summ = 2
	if x == 0:
		a.append(4)
	elif x == 1:
		a.append(3)
	elif x == 2:
		a.append(2)
	else:
		x -= summ
		a.append(summ - x)
for i in range(n):
	print(a[i])


itter = int(input())
res = ''
for i in range(0, itter):
	spi = int(input())
	if spi == 2:
		res += '2\n'
	elif spi % 2 == 0:
		res += '0\n'
	else:
		res += '1\n'
print(res[:-1])


import os
import sys
from io import BytesIO, IOBase

def solution(n):
	if n == 2:
		write(2)
		return
	write(n % 2)

def main():
	for _ in range(r_int()):
		n = r_int()
		solution(n)
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))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(end)

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

def r_int():
	return int(input())
main()


i1 = int(input())
i2 = []
for i in range(i1):
	x = int(input())
	i2.append(x)
for j in i2:
	if j == 1:
		print(2)
	elif j == 2:
		print(2)
	elif j % 2 == 0:
		print(0)
	else:
		print(1)


for i in range(int(input())):
	number = int(input())
	if number % 2 == 0 and number != 2 and (number != 0):
		print(0)
		continue
	else:
		if number == 2:
			print(2)
			continue
		elif number == 0:
			print(4)
			continue
		elif number == 1:
			print(3)
			continue
		print(1)


t = int(input())
while t > 0:
	n = int(input())
	print(2 if n == 2 else n & 1)
	t -= 1


k = []
a = 0
b = 0
c = 0
for i in range(int(input())):
	k.append(int(input()))
for i in k:
	a = i // 2
	c = i - a
	b = c - a
	if i == 2:
		print(2)
		continue
	print(a + b + c - i)


def get_int_input():
	return int(input())

def main():
	q = get_int_input()
	examples = []
	for example in range(q):
		examples.append(get_int_input())
	for example in examples:
		if example == 2:
			print(2)
		elif example % 2 == 0:
			print(0)
		else:
			print(1)
main()


n = int(input())
s = []
i = 0
g = n
while n != 0:
	a = int(input())
	if a == 0:
		b = 4
		s.append(b)
	elif a == 1:
		b = 3
		s.append(b)
	elif a == 2:
		b = 2
		s.append(b)
	elif a == 3:
		b = 1
		s.append(b)
	elif a % 2 == 0:
		b = 0
		s.append(b)
	elif a % 2 != 0:
		b = a % 2
		s.append(b)
	n = n - 1
s.reverse()
while i in range(g):
	print(s[g - 1])
	g = g - 1


q = int(input())
for qq in range(q):
	n = int(input())
	if n <= 4:
		print(4 - n)
	else:
		print((n + 1) // 2 * 2 - n)


q = int(input())

def f(n):
	if n == 1:
		return 3
	if n == 2:
		return 2
	if n % 2 == 0:
		return 0
	if n % 2 == 1:
		return 1
l = []
for i in range(q):
	n = int(input())
	l += [f(n)]
for i in l:
	print(i)


def main():
	q = int(input())
	for i in range(q):
		n = int(input())
		if n >= 4 and n % 2 == 0:
			print(0)
		elif n == 2:
			print(2)
		else:
			print(1)
main()


t = int(input())
for i in range(t):
	n = int(input())
	if n == 2:
		print(2)
	elif n % 2 != 0:
		print(1)
	elif n > 2 and n % 2 == 0:
		print(0)


s = int(input())
for i in range(s):
	n = int(input())
	if n == 2:
		print('2')
		continue
	if n == 1:
		print('3')
		continue
	if n % 2 == 0:
		print('0')
	else:
		print('1')


ochz = int(input())
a = []
while ochz != 0:
	chspich = int(input())
	a.append(chspich)
	ochz -= 1
for i in a:
	if i % 2 == 0 and i != 2:
		print(0)
	elif i == 2:
		print(2)
	else:
		print(1)


q = int(input())
s = []
for i in range(q):
	n = int(input())
	if n % 2 != 0:
		s.append(1)
	elif n % 2 == 0 and n != 2:
		s.append(0)
	else:
		s.append(2)
for i in range(q):
	print(s[i])


for _ in range(int(input())):
	a = int(input())
	print([a % 2, 4 - a][a <= 4])


q = int(input())
s = 0
p = 0
res = 0
for i in range(q):
	n = int(input())
	if n % 2 != 0:
		s = n // 2
		p = n - s
		res = p - s
		print(res)
	if n == 2:
		print(2)
		continue
	if n % 2 == 0 and n != 2:
		print(0)


import math as m
q = int(input())
(n, res) = (0, 0)
for i in range(q):
	n = int(input())
	if n == 2:
		print(2)
	else:
		res = m.ceil(n / 2)
		print(int(abs(n - 2 * res)))


n = int(input())
a = []
for i in range(n):
	k = int(input())
	a.append(k)
for i in a:
	if i % 2 == 0 and i // 2 > 1:
		print(0)
	elif i % 2 == 0:
		print(2)
	else:
		for j in range(i + 1):
			if (i + j) % 2 == 0 and (i + j) // 2 > 1:
				print(j)
				break


res = []
for _ in range(int(input())):
	n = int(input())
	if n < 4:
		res.append(4 - n)
	else:
		res.append(n % 2)
for i in res:
	print(i)


def find_matches(n):
	if n == 2:
		return 2
	if n % 2 == 0:
		return 0
	else:
		return 1
queries = int(input())
for query in range(queries):
	n = int(input())
	print(find_matches(n))


for i in [0] * int(input()):
	a = int(input())
	if a >= 4:
		print(a % 2)
	else:
		print(4 - a)


q = int(input())
n = 0
m = []
b = 1
p = 0
while p < q:
	n = int(input())
	if n == 2:
		m.append(2)
	elif n % 2 == 0:
		m.append(0)
	elif n % 2 != 0:
		m.append(1)
	p += 1
for i in range(len(m)):
	print(m[i])


k = int(input())
for _ in range(k):
	n = int(input())
	if n == 1 or n == 2:
		print('2')
	elif n % 2 == 0:
		print('0')
	else:
		print('1')


def find(x):
	if x == 2:
		return 2
	if x % 2 == 0:
		return 0
	else:
		return 1
for i in range(int(input())):
	x = int(input())
	print(find(x))


n = int(input())
for i in range(n):
	s = int(input())
	if s == 2:
		print(2)
	else:
		print(s % 2)


for _ in ' ' * int(input()):
	a = int(input())
	if a < 4:
		print(4 - a)
	else:
		print(a % 2)


a = int(input())
answers = []
for i in range(a):
	i = int(input())
	if i != 2:
		if i % 2 == 0 and i >= 4:
			answers.append('0')
		else:
			answers.append('1')
	else:
		answers.append('2')
for i in answers:
	print(i)


a = int(input())
c = []
for i in range(a):
	x = int(input())
	if x < 4:
		c.append(4 - x)
	else:
		c.append(x % 2)
for i in c:
	print(i)


n = int(input())
q = []
for i in range(n):
	a = int(input())
	if a == 2:
		q1 = 2
	elif a % 2 == 0:
		q1 = 0
	else:
		q1 = 1
	q.append(q1)
for i in q:
	print(i)


q = int(input())
while q:
	n = int(input())
	if n == 2:
		print(2)
	else:
		print(n % 2)
	q -= 1


import math
q = int(input())
b = []
for i in range(q):
	a = int(input())
	if a % 2 == 0 and a != 2:
		b.append(0)
	elif a == 2:
		b.append(2)
	else:
		b.append(math.ceil(a / 2) * 2 - a)
for i in range(q):
	print(b[i])


for i in range(int(input())):
	x = int(input())
	print(max(4, x + x % 2) - x)


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import Decimal
from decimal import *
from collections import defaultdict, deque
import heapq
from decimal import Decimal
getcontext().prec = 25
abcd = 'abcdefghijklmnopqrstuvwxyz'
MOD = 1000000007
BUFSIZE = 8192
from bisect import bisect_left, bisect_right

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')
for _ in range(int(input())):
	n = int(input())
	if n <= 3:
		print(4 - n)
	elif n % 2:
		print(1)
	else:
		print(0)


n = int(input())
b = []
for i in range(n):
	a = int(input())
	if a == 2:
		c = 2
	elif a % 2 == 0:
		c = 0
	else:
		c = 1
	b += [c]
for i in b:
	print(i)


a = int(input())
for i in range(a):
	c = int(input())
	if c == 2:
		print(2)
	else:
		print(c % 2)


q = int(input())
for i in range(q):
	m = int(input())
	c = m
	if m == 2:
		m += 2
	while m % 2 != 0:
		m += 1
	print(m - c)


a = int(input())
for i in range(a):
	b = int(input())
	print(max(b % 2, 4 - b))


q = int(input())
mas = [0] * q
for i in range(q):
	mas[i] = int(input())
for i in range(q):
	if mas[i] < 4:
		print(4 - mas[i])
	elif mas[i] % 2 == 0:
		print(0)
	else:
		print(mas[i] // 2 * 2 + 2 - mas[i])


n = int(input())
while n > 0:
	ehfdytybt = int(input())
	if ehfdytybt < 4:
		print(4 - ehfdytybt)
	elif ehfdytybt % 2 == 0:
		print(0)
	else:
		print(1)
	n = n - 1


q = int(input())
a = list()
for i in range(q):
	n = int(input())
	if n % 2 == 0 and n > 3:
		a.append(0)
	elif n > 3:
		j = 0
		while not n % 2 == 0:
			n += 1
			j += 1
		a.append(j)
	else:
		a.append(4 - n)
for i in a:
	print(i)


def simple(n):
	ans = 0
	if not n % 2 == 0:
		ans += 1
		n += 1
	if n // 2 <= 1:
		ans += 2
		n += 2
	return ans
nn = int(input())
for i in range(0, nn):
	print(simple(int(input())))


import sys
import math
counter = -1
count = 0
for lin in sys.stdin:
	line = lin.rstrip()
	counter += 1
	if counter == 0:
		count = int(line)
	elif counter <= count:
		a = int(line)
		if a == 1:
			print('3')
		elif a == 2:
			print('2')
		elif a % 2 == 0:
			print('0')
		else:
			print('1')
	else:
		break


n = int(input())
for i in range(n):
	t = int(input())
	print(max(t % 2, 4 - t))


q = int(input())
pr = []
for z in range(q):
	n = int(input())
	if n > 4:
		pr.append(n % 2)
	else:
		pr.append(4 - n)
for e in pr:
	print(e)


n = int(input())
B = []
for i in range(n):
	k = int(input())
	if k % 2 == 0 and k >= 4:
		B.append(0)
	elif k < 4:
		B.append(4 - k)
	else:
		B.append(1)
for i in B:
	print(i)


from sys import stdin, stdout
from collections import *
from math import ceil, floor, log, gcd
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')

def solve():
	n = inp()
	if n & 1:
		pr(1)
	elif n == 2:
		pr(2)
	else:
		pr(0)
for _ in range(inp()):
	solve()


x = int(input())
i = 0
while i < x:
	i = i + 1
	p = int(input(''))
	if p == 2:
		print('2')
	elif p % 2 == 0:
		print('0')
	else:
		print('1')


def main():
	n = int(input())
	for _ in range(n):
		x = int(input())
		if x == 2:
			print(2)
		elif x % 2 == 0:
			print(0)
		else:
			print(1)
main()


t = int(input())
for i in range(t):
	x = int(input())
	print(2 if x == 2 else x % 2)


q = int(input())
for i in range(0, q):
	x = int(input())
	if x > 3:
		print(x % 2)
	elif 0 < x < 4:
		print(4 - x)


n = int(input())
t = []
d = 0
for i in range(n):
	a = int(input())
	t.append(a)
for i in range(len(t)):
	if t[i] % 2 == 0 and t[i] != 2:
		print(0)
	elif t[i] == 2:
		print(2)
	elif t[i] % 2 != 0 and t[i] > 2:
		print(1)
	elif t[i] == 0:
		print(4)
	elif t[i] == 1:
		print(3)


ans = []
q = int(input())
for i in range(q):
	a = int(input())
	if a % 2 == 0 and a >= 4:
		ans.append('0')
	elif a == 2:
		ans.append('2')
	else:
		ans.append('1')
for i in range(q):
	print(ans[i])


for _ in range(int(input())):
	inp = int(input())
	if inp == 2:
		print(2)
		continue
	print(inp % 2)


n = int(input())
for i in range(n):
	a = int(input())
	if a < 4:
		print(4 - a)
		continue
	if a % 2 == 1:
		print(1)
		continue
	else:
		print(0)
		continue


for _ in range(int(input())):
	c = int(input())
	if c == 2:
		print(2)
	else:
		print(c % 2)


q = int(input())
for i in range(q):
	t = int(input())
	if t < 4 and t != 0:
		otv = 4 - t
		print(otv)
	elif t % 2 == 0:
		print(0)
	else:
		print(1)


__author__ = '#miner'
for i in range(int(input())):
	a = int(input())
	print(2 if a == 2 else a % 2)


q = int(input())
for i in range(q):
	x = int(input())
	if x >= 4 and x % 2 == 0:
		print(0)
	if x >= 4 and x % 2 == 1:
		print(1)
	if x == 2:
		print(2)
	if x == 3:
		print(1)


import array

def solution():
	req = int(input())
	for i in range(req):
		count = int(input())
		result = 0
		if count == 2:
			print(2)
			continue
		while count % 2 != 0:
			result += 1
			count += 1
		print(result)

def count_of_one(number):
	result = 0
	while number:
		result += number % 2
		number //= 2
	return result

def to_mixed_frac(first, second):
	while True:
		for i in range(2, first + 1):
			if first % i == 0 and second % i == 0:
				first //= i
				second //= i
				break
		else:
			break
	return str(first) + '/' + str(second)

def array_to_int(array):
	for i in range(len(array)):
		array[i] = int(array[i])
	return array

def join0(array):
	result = ''
	for i in array:
		result += str(i)
	return result

def replace(string, new_ch, index):
	new_str = ''
	for i in range(len(string)):
		if i == index:
			new_str += new_ch
		else:
			new_str += string[i]
	return new_str
solution()


import math
q = int(input())
while q:
	n = int(input())
	if n == 2:
		print(2)
	elif n % 2 == 0:
		print(0)
	else:
		print(1)
	q = q - 1


import math
x = list(map(int, input().split()))
s = []
q = []
counter = 0
for i in range(0, x[0]):
	s.append(int(input()))
for i in range(0, x[0]):
	if s[i] == 2:
		q.append(2)
	else:
		q.append(s[i] % 2)
for i in range(0, x[0]):
	print(q[i])


for i in range(int(input())):
	inp = int(input())
	try:
		assert inp > 2
		val1 = inp // 2
		assert inp % 2 == 0
		print(0)
		continue
	except AssertionError:
		if inp < 4:
			print(4 - inp)
			continue
		print(1)


from math import *
from copy import *
from string import *
from random import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math

def bin1(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = k ** mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin1(mid + 1, r, k, t, b, val, ans)
		else:
			return bin1(l, mid - 1, k, t, b, val, ans)

def bin2(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = t * k ** mid + b * mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin2(l, mid - 1, k, t, b, val, ans)
		else:
			return bin2(mid + 1, r, k, t, b, val, ans)

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
	l = []
	for i in range(2, n + 1):
		if prime[i]:
			l.append(i)
	return l

def bin(l, r, ll, val):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		if val >= ll[mid][0] and val <= ll[mid][1]:
			return mid
		elif val < ll[mid][0]:
			return bin(l, mid - 1, ll, val)
		else:
			return bin(mid + 1, r, ll, val)

def deci(n):
	s = ''
	while n != 0:
		if n % 2 == 0:
			n = n // 2
			s = '0' + s
		else:
			n = n // 2
			s = '1' + s
	return s

def diff(s1, s2):
	if len(s1) < len(s2):
		v = len(s1)
		while v != len(s2):
			s1 = '0' + s1
			v = v + 1
	else:
		v = len(s2)
		while v != len(s1):
			s2 = '0' + s2
			v = v + 1
	c = 0
	for i in range(len(s1)):
		if s1[i:i + 1] != s2[i:i + 1]:
			c = c + 1
	return c
from sys import stdin, stdout

def fac(a, b):
	v = a
	while a != b:
		v *= a - 1
		a = a - 1
	return v

def bino(l, r, n):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		val1 = math.log(n / mid + 1, 2)
		val2 = int(val1)
		if val1 == val2:
			return val1
		elif val1 < 1.0:
			return bino(l, mid - 1, n)
		else:
			return bino(mid + 1, r, n)

def binary(l, r, ll, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		if ll[mid] == val:
			return ll[mid]
		elif ll[mid] < val:
			ans = ll[mid]
			return binary(mid + 1, r, ll, val, ans)
		else:
			return binary(l, mid - 1, ll, val, ans)

def check(n):
	v = 1
	while n != 0:
		if n % 10 == 0 or n % 10 == 1:
			n = n // 10
		else:
			v = 0
			break
	return v
t = int(input())
for i in range(t):
	n = int(input())
	if n % 2 == 0:
		if n == 2:
			print(2)
		else:
			print(0)
	else:
		print(1)


def main():
	q = int(input())
	for i in range(q):
		s = int(input())
		if s < 3:
			print(4 - s)
		else:
			print(s % 2)
	return 0
main()


def spi(e):
	if e == 1:
		return 3
	elif e == 2:
		return 2
	elif e == 3:
		return 1
	else:
		return e % 2
q = int(input())
b = []
for i in range(q):
	b.append(int(input()))
for i in range(q):
	print(spi(b[i]))


from math import ceil
n = int(input())
for i in range(n):
	x = int(input())
	if x < 4:
		print(4 - x)
	else:
		print(x % 2)


T = int(input())
L = []
for i in range(T):
	L.append(int(input()))
for i in L:
	print(2 if i == 2 else 0 if i != 2 and i % 2 == 0 else 1)


q = int(input())
queries = [int(input()) for _ in range(q)]
for n in queries:
	if n == 2:
		print(2)
	elif not n % 2:
		print(0)
	else:
		print(1)


queries = int(input(''))
answer = []
for i in range(queries):
	n = int(input(''))
	if n == 2:
		answer.append('2')
	elif n % 2 == 0:
		answer.append('0')
	else:
		answer.append('1')
for j in answer:
	print(j)


t = int(input())
for c in range(t):
	n = int(input())
	print(2 if n == 2 else n % 2)


t = int(input())
for i in range(t):
	num = int(input())
	if num < 4:
		print(4 - num)
	elif num % 2 == 0:
		print(0)
	else:
		print(1)


q = int(input())
queue = []
for _ in range(q):
	n = int(input())
	if n == 2:
		queue.append(2)
	elif n % 2 == 0:
		queue.append(0)
	else:
		queue.append(1)
for i in queue:
	print(i)


q = int(input())
while q > 0:
	n = int(input())
	a = 2
	n = n - 2
	if n < a:
		ans = a - n
		print(ans)
	elif n == a:
		print('0')
	elif n > a:
		ans = n - a
		if ans % 2 == 0:
			print('0')
		else:
			print('1')
	q = q - 1


q = int(input())
a = []
for x in range(q):
	a.append(int(input()))
for elem in a:
	if elem == 2:
		print(2)
	elif elem % 2 == 0:
		print(0)
	else:
		print(1)


t = int(input())
for _ in range(t):
	q = int(input())
	print(q % 2 + 2 * bool(q == 2))


def f(x):
	if x == 2:
		return 2
	if x % 2 == 0:
		return 0
	else:
		return 1
N = int(input())
for i in range(N):
	print(f(int(input())))


for j in range(int(input())):
	s = int(input())
	if s == 2:
		print(2)
	elif s % 2 == 0:
		print(0)
	else:
		print(1)


for _ in range(int(input())):
	n = int(input())
	k = 0
	while n < 4 or n % 2 == 1:
		k += 1
		n += 1
	print(k)


test_cases = int(input())
for i in range(test_cases):
	sticks = int(input())
	if sticks == 2:
		print(2)
	elif sticks % 2 == 0:
		print(0)
	else:
		print(1)


q = int(input())
a = 0
z = 0
for i in range(0, q):
	a = int(input())
	if a % 2 == 1:
		z = 1
	else:
		z = 0
	if a < 4:
		z = 4 - a
	print(z)


n = int(input())
for i in range(n):
	p = int(input())
	if p == 2:
		print(2)
	else:
		print(p % 2)


q = int(input())
results = []
for _ in range(q):
	a = int(input())
	if a < 4:
		results.append(4 - a)
	elif a % 2:
		results.append(1)
	else:
		results.append(0)
for a in results:
	print(a)


for i in range(int(input())):
	q = int(input())
	print(max(4 - q, q % 2))


a = int(input())
for i in range(0, a):
	b = int(input())
	if b % 2 == 0:
		if b == 2:
			print(2)
		else:
			print(0)
	if b % 2 != 0:
		if b == 1:
			print(3)
		else:
			print(1)


a = int(input())
gg = []
for i in range(a):
	gg.append(int(input()))
for i in gg:
	ggg = True
	if i <= 4:
		print(4 - i)
		ggg = False
	if i % 2 == 0 and ggg:
		print(0)
	elif ggg:
		print(1)


for tc in range(int(input())):
	x = int(input())
	if x == 1:
		print(3)
	elif x == 2:
		print(2)
	else:
		print(x % 2)


T = int(input())
for t in range(T):
	m = int(input())
	if m == 2:
		print(2)
	else:
		print(m % 2)


q = int(input())
javab = []
for i in range(q):
	n = int(input())
	if n == 2:
		javab.append(2)
		continue
	if n % 2 == 0:
		javab.append(0)
		continue
	test_1 = n // 2 + 1
	javab.append(test_1 * 2 - n)
for i in range(q):
	print(javab[i])


n = int(input())
sum = 0
for file in range(n):
	i = int(input())
	if i == 2:
		print(2)
	elif i == 3:
		print(1)
	elif i % 2 == 0:
		print(0)
	else:
		print(1)


for i in range(int(input())):
	n = int(input())
	print(2 if n is 2 else n % 2)


for _ in range(int(input())):
	a = int(input())
	b = a % 2
	if a == 2:
		print(2)
	elif b == 1:
		print(1)
	else:
		print(0)


q = int(input())
for i in range(0, q):
	n = int(input())
	if n < 4:
		print(4 - n)
		continue
	print(n % 2)


c = int(input())
l = []
r = 0
for i in range(c):
	l.append(int(input()))
for i in range(len(l)):
	if l[i] == 2:
		print(2)
	elif l[i] % 2 == 0:
		print(0)
	else:
		r = int(l[i] / 2) + 1
		print(1)


n = []
q = int(input())
for k in range(q):
	l = 0
	l = int(input())
	if l == 1 or l == 2:
		n.append(2)
	elif l % 2 == 1:
		n.append(1)
	else:
		n.append(0)
for i in range(q):
	print(n[i])


q = int(input())
for tmp in range(q):
	n = int(input())
	ans = n % 2 if n >= 4 else 4 - n
	print(ans)


n = int(input())
ans = []
for _ in range(n):
	a = int(input())
	if a < 4:
		print(4 - a)
	else:
		print(a % 2)
for el in ans:
	print(el)


def foo(x):
	if x % 2:
		print(1)
	elif x == 2:
		print(2)
	else:
		print(0)
test = int(input())
for each in range(test):
	foo(int(input()))


q = int(input())
ans = []

def countMatches(n):
	if n == 2:
		return 2
	elif n % 2 == 0:
		return 0
	else:
		return 1
	return ans
for i in range(q):
	ans.append(countMatches(int(input())))
for i in ans:
	print(str(i))


n = int(input())
mass = []
for i in range(n):
	x = int(input())
	mass.append(x)
for i in range(mass.__len__()):
	if mass[i] == 2:
		print(2)
	elif mass[i] % 2 == 0:
		print(0)
	elif mass[i] % 2 == 1:
		print(1)


from math import ceil
k = int(input())
for _ in range(k):
	n = int(input())
	if n <= 4:
		print(4 - n)
	else:
		c = ceil(n / 2)
		print(c - (n - c))


n = int(input())
for i in range(n):
	num = int(input())
	if num == 2:
		print(2)
	else:
		print(num % 2)


count = int(input())
data = []
for i in range(count):
	data.append(int(input()))
for number in data:
	if number >= 4:
		if number % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		print(4 - number)


from math import ceil
for i in range(int(input())):
	n = int(input())
	print((ceil(n / 2) - n // 2, 2)[n < 3])


k = int(input())
for i in range(k):
	g = 0
	n = int(input())
	if n < 4:
		print(4 - n)
	else:
		if n % 2 != 0:
			n += 1
			g += 1
		s = n // 2
		print(g)


from math import modf
queries = int(input())
outputs = []
for i in range(queries):
	n = int(input())
	B = 0
	c = (B + n) / 2
	while modf(c)[0] != 0.0 or c < 2:
		B += 1
		c = (B + n) / 2
	outputs.append(B)
for output in outputs:
	print(output)


n = int(input())
l = []
for _ in range(n):
	temp = int(input())
	l.append(temp)
for i in range(n):
	if l[i] < 4:
		print(4 - l[i])
	elif l[i] % 2 == 0:
		print(0)
	else:
		print(1)


q = int(input())
for i in range(q):
	n = int(input())
	if n % 2 == 0 and n >= 4:
		print('0')
	if n % 2 == 0 and n < 4:
		print('2')
	if n % 2 == 1:
		print('1')


d = int(input())
for i in range(d):
	N = int(input())
	if N < 5:
		print(4 - N)
	else:
		print(N % 2)


for i in range(int(input())):
	a = int(input())
	if a > 2:
		if not a % 2:
			print(0)
		else:
			print(1)
	else:
		print(4 - a)


a = []
n = int(input())
for i in range(n):
	new_element = int(input())
	a.append(new_element)
	k = 0
for i in range(n):
	if a[k] == 2:
		print(2)
		k += 1
	elif a[k] % 2 == 0:
		print(0)
		k += 1
	else:
		print(a[k] % 2)
		k += 1


numinput = int(input())
num = []
for i in range(0, numinput):
	query = int(input())
	num.append(query)
for i in range(0, numinput):
	if num[i] < 4:
		output = 4 - num[i]
	elif num[i] == 4:
		output = 0
	elif num[i] % 2 != 0:
		output = 1
	else:
		output = 0
	print(output)


for j in range(int(input())):
	i = int(input())
	if i == 1:
		print(3)
	elif i == 2:
		print(2)
	elif i % 2 == 0 and i != 2:
		print(0)
	elif i % 2 != 0 and i != 1:
		print(1)


t = int(input())
for i in range(t):
	n = int(input())
	if n == 2:
		print('2')
	else:
		print(n % 2)


m = int(input())
n = 0
num = []
for i in range(0, m):
	num.insert(i, int(input()))
for i in range(0, m):
	n = 0
	if num[i] % 2 != 0 and num[i] is 1:
		n += 3
	if num[i] % 2 != 0 and num[i] > 1:
		n += 1
	if num[i] % 2 is 0 and num[i] == 2:
		n += 2
	print(n)


import math
n = int(input())
array = []
for i in range(n):
	num = int(input())
	if num == 2:
		array.append(2)
		continue
	a = math.floor(num / 2)
	b = num - a
	array.append(b - a)
for num in array:
	print(num)


n = int(input())
lst = []
lst1 = []
for i in range(n):
	lst.append(int(input()))

def a(n):
	if n == 0:
		return 4
	if n == 1:
		return 3
	if n == 2:
		return 2
	if n % 2 == 0:
		return 0
	if n % 2 != 0:
		return 1
for i in lst:
	print(a(i))


n = int(input())
lis = [int(input()) for i in range(n)]
for i in lis:
	if i != 2:
		print(i % 2)
	else:
		print(2)


number_of_queries = int(input())
x = []
for i in range(0, number_of_queries):
	a = input()
	x.append(int(a))
for i in range(0, number_of_queries):
	if x[i] < 4:
		print(4 - x[i])
	else:
		print(x[i] % 2)


q = int(input())
for t in range(0, q, 1):
	n = int(input())
	if n <= 3:
		print(4 - n)
	elif n % 2 == 0:
		print('0')
	else:
		c = int((n + 1) / 2)
		b = int(c - 1)
		a = int(1)
		print(abs(n - (a + b + c)))


import sys
DEBUG = 0
(FSTREAM_IN, FSTREAM_OUT) = (DEBUG, DEBUG)
(FILENAME_IN, FILENAME_OUT) = ('in.txt', 'out.txt')

def main():
	q = int(input())
	for i in range(q):
		n = int(input())
		print(n % 2 if n != 2 else 2)
if DEBUG:
	(FILENAME_IN, FILENAME_OUT) = ('debug.in', 'debug.out')
if FSTREAM_IN:
	sys.stdin = open(FILENAME_IN, 'r')
if FSTREAM_OUT:
	sys.stdout = open(FILENAME_OUT, 'w')
main()


def main():
	q = int(input())
	for i in range(q):
		n = int(input())
		if n < 4:
			print(4 - n)
		else:
			print(n % 2)
main()


import math
n = int(input())
q = []
for x in range(0, n):
	num = int(input())
	c = math.ceil(num / 2)
	if num < 4:
		c = 2
	y = 2 * c - num
	q.append(y)
for qu in q:
	print(qu)


def CME(n):
	if n == 2:
		return 2
	if n % 2 == 1:
		return 1
	if n % 2 == 0:
		return 0
q = int(input())
for i in range(q):
	n = int(input())
	print(CME(n))


def amount(n: int):
	if n % 2 != 0:
		return 1
	if n == 2:
		return 2
	return 0
q = int(input())
num = []
for i in range(q):
	n = int(input())
	num.append(n)
for i in num:
	print(amount(i))


n = int(input())
a = [''] * n
q = [''] * n
for i in range(n):
	a[i] = a[i].replace('', input())
	if int(a[i]) == 2:
		q[i] = q[i].replace('', str(2))
	else:
		q[i] = q[i].replace('', str(int(a[i]) % 2))
for i in range(n):
	print(q[i])


for i in ' ' * int(input()):
	n = int(input())
	d = 0
	c = (n + d) / 2
	while not c.is_integer() or c < 2:
		d += 1
		c = (n + d) / 2
	print(d)


num = int(input())
for i in range(num):
	number = int(input())
	if number == 2:
		print(2)
	elif number % 2 == 0:
		print(0)
	elif number % 2 != 0:
		print(1)


q = int(input())
for j in range(q):
	n = int(input())
	m = 0
	while n < 4:
		m += 1
		n += 1
	if n % 2 != 0:
		n += 1
		m += 1
	print(m)


n = int(input())
current = []
buy = []
for i in range(n):
	current.append(int(input()))
for i in current:
	if i < 4:
		buy.append(4 - i)
	elif i % 2 == 0:
		buy.append(0)
	else:
		buy.append(1)
for i in buy:
	print(i)


q = int(input())
num = []
ans = []
for i in range(q):
	num.append(int(input()))
for n in num:
	if n == 2:
		ans.append(2)
	else:
		c = n // 2
		if n == 2 * c:
			ans.append(0)
		else:
			ans.append(1)
for el in ans:
	print(el)


q = int(input())
b = 0
r = 0
while b != q:
	n = int(input())
	if n % 2 == 0:
		r = 0
	if n % 2 == 1:
		r = 1
	if n == 2:
		r = 2
	print(r)
	b += 1


q = int(input())
a = []
b = int()
c = 0
z = []
for i in range(q):
	x = int(input())
	a.append(x)
for i in range(q):
	c = 0
	b = a[i]
	while b % 2 != 0 or b <= 2:
		c += 1
		b += 1
	z.append(c)
for i in range(q):
	print(z[i])


n = int(input())
for i in range(n):
	z = int(input())
	if z >= 4:
		if z % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		print(4 - z)


count = int(input())
results = []
for i in range(count):
	n = int(input())
	res = 0
	while n % 2 != 0 or n < 4:
		res += 1
		n += 1
	results.append(res)
for r in results:
	print(r)


q = int(input())
result = []

def which(n):
	if n == 2:
		return 2
	if n % 2 == 0:
		return 0
	if n % 2 == 1:
		return 1
for i in range(q):
	n = int(input())
	result.append(which(n))
for i in result:
	print(i)


n = int(input())
for i in range(n):
	d = int(input())
	print(max(4 - d, d % 2))


import math
a = int(input())
b = []
for i in range(a):
	b.append(int(input()))
for i in b:
	if i == 2:
		print(2)
	else:
		print(math.ceil(i / 2) - math.ceil(i - math.ceil(i / 2)))


q = int(input())
n = 0
docup = 0
mn1 = 0
mn2 = 0
l = []
for i in range(q):
	n = int(input())
	l.append(str(n))
for i in l:
	if int(i) == 2:
		print(2)
	else:
		mn1 = 1
		mn2 = (int(i) - 1) // 2
		docup = mn1 + mn2 - int(i) // 2
		print(docup)
		docup = 0


qnum = int(input())
reqs = []
for i in range(qnum):
	reqs.append(int(input()))
for item in reqs:
	if item == 2:
		print(2)
	elif item % 2 == 0:
		print(0)
	else:
		print(1)


q = int(input())
otv = []
for i in range(q):
	n = int(input())
	if n == 2:
		otv.append(2)
	elif n % 2 == 0:
		otv.append(0)
	else:
		otv.append(1)
for x in otv:
	print(x)


q = int(input())
for _ in range(q):
	matches = int(input())
	buy = 0
	if matches == 2:
		buy = 2
	elif matches % 2 != 0:
		buy = 1
	print(buy)


y = int(input())
a = []
for i in range(y):
	n = int(input())
	if n % 2 == 0:
		n //= 2
		if n > 1:
			a.append('0')
		else:
			a.append('2')
	elif n > 1:
		a.append('1')
	else:
		a.append('3')
for i in range(y):
	print(a[i])


n = int(input())
ans = []
for _ in range(n):
	n_matches = int(input())
	if n_matches < 4:
		ans.append(4 - n_matches)
	elif n_matches % 2 == 0:
		ans.append(0)
	else:
		ans.append(1)
for a in ans:
	print(a)


for c in range(int(input())):
	a = int(input())
	if a < 4:
		print(4 - a)
	elif a % 2 == 0:
		print(0)
	else:
		print(1)


def main():
	query_count = int(input())
	matches_list = []
	for i in range(query_count):
		matches_list.append(int(input()))
	for matches in matches_list:
		if matches < 4:
			print(4 - matches)
		elif matches % 2 != 0:
			print(1)
		else:
			print(0)
main()


am = int(input())
for i in range(am):
	a = int(input())
	if a == 2 or a == 1:
		print(4 - a)
	elif a % 2 == 0:
		print(0)
	else:
		print(1)


n = int(input())
for i in range(n):
	a = int(input())
	b = 0
	while not ((a + b) % 2 == 0 and (a + b) / 2 > 1):
		b += 1
	print(b)


import math
x = int(input())
a = [0] * x
for i in range(x):
	a[i] = int(input())
for k in range(x):
	if a[k] == 2:
		print(2)
	else:
		h = a[k] / 2
		h = math.ceil(h)
		print(2 * h - a[k])


arr = []
for i in range(int(input())):
	n = int(input())
	if n < 4:
		arr.append(4 - n)
	else:
		pr = n // 2
		vt = n // 2
		cnt = 0
		if n % 2 == 1:
			arr.append(1)
		else:
			arr.append(0)
for i in arr:
	print(i)


t = int(input())
answer = []
for a in range(t):
	val = int(input())
	if val == 2:
		answer.append(2)
	elif val % 2 == 1:
		answer.append(1)
	else:
		answer.append(0)
for b in answer:
	print(str(b))


def f(n):
	if n == 2:
		print(2)
	elif n % 2 == 1:
		print(1)
	else:
		print(0)
q = input()
for i in range(int(q)):
	x = input()
	f(int(x))


n = int(input())
for i in '"' * n:
	n = int(input())
	print(max(4 - n, n % 2))


n = int(input())
count = 0
l = []
while count < n:
	x = int(input())
	l.append(x)
	count += 1
for s in l:
	if s < 4:
		print(4 - s)
	elif s % 2 == 0:
		print(0)
	else:
		print(1)


t = int(input())
while t > 0:
	t -= 1
	a = int(input())
	if a == 2:
		print(2)
	else:
		print(a % 2)


for _ in range(int(input())):
	N = int(input())
	if N > 2:
		print(1 if N % 2 != 0 else 0)
	else:
		print(2)


def s(n):
	if n > 3 and n % 2 == 0:
		print(0)
	elif n == 3:
		print(1)
	elif n == 2:
		print(2)
	elif n == 1:
		print(3)
	elif n == 0:
		print(4)
	else:
		print(1)

def kol(g):
	for i in range(g):
		n = int(input())
		s(n)
g = int(input())
kol(g)


n = int(input())
li = []
for i in range(n):
	li.append(int(input()))
for i in range(len(li)):
	if li[i] == 2:
		print('2')
	elif li[i] % 2 == 0:
		print('0')
	else:
		print('1')


a = int(input())
b = []
for i in range(a):
	b.append(int(input()))
for i in range(len(b)):
	m = b[i]
	if m == 2:
		print('2')
	elif m % 2 == 0:
		print('0')
	else:
		print('1')


n = int(input())
l = []
res = []
for i in range(n):
	l.append(int(input()))
for el in l:
	if el <= 4:
		res.append(4 - el)
	else:
		res.append(el % 2)
for el in res:
	print(el)


ans = []
for i in range(int(input())):
	n = int(input())
	count = max(n % 2, 4 - n)
	ans.append(count)
for i in ans:
	print(i)


n = int(input())
list = []
for i in range(n):
	list.append(int(input()))
for j in range(n):
	if list[j] == 2:
		print(2)
	elif list[j] % 2 == 0:
		print(0)
	elif list[j] % 2 == 1:
		print(1)


rng = int(input())
for _ in range(rng):
	a = int(input())
	if (a % 2 == 0) & (a >= 4):
		print(0)
	elif a == 2:
		print(2)
	else:
		print(1)


t = int(input())
while t:
	x = 0
	n = int(input())
	if n == 2:
		x = 2
	elif n != 2 and n % 2 == 0:
		x = 0
	elif n % 2 != 0:
		x = 1
	print(x)
	t -= 1


A = []
for i in range(int(input())):
	a = int(input())
	if a == 2:
		A.append(2)
	else:
		A.append(a % 2)
for a in A:
	print(a)


q = int(input())
for i in range(q):
	c = int(input())
	if c == 2:
		print(2)
	else:
		print(c % 2)


def kus(a):
	if a % 2 == 0 and a >= 4:
		return 0
	if 0 <= a < 4:
		return 4 - a
	elif a % 2 == 1:
		return 1
for i in range(int(input())):
	a = int(input())
	print(kus(a))


for i in range(int(input())):
	x = int(input())
	if x > 3:
		if x % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		print(4 - x)


from sys import stdin, stdout
anzahl = int(stdin.readline().rstrip())
for x in range(0, anzahl):
	n = int(stdin.readline().rstrip())
	if n > 2 and n % 2 == 0:
		stdout.write(str(0) + '\n')
	elif n == 2:
		stdout.write(str(2) + '\n')
	else:
		stdout.write(str(1) + '\n')


q = int(input())
lst = list()
for i in range(q):
	n = int(input())
	lst.append(n)
for z in lst:
	if z == 2:
		print('2')
	elif z % 2 == 0:
		print('0')
	elif z % 2 != 0:
		print('1')


for nt in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
		continue
	if n % 2:
		print(1)
	else:
		print(0)


def solve(n):
	if n <= 4:
		return 4 - n
	return n % 2
t = int(input())
res = list()
for _ in range(0, t):
	n = int(input())
	res.append(solve(n))
for result in res:
	print(result)


q = int(input())
r = []
for i in range(q):
	g = int(input())
	if g == 2:
		r.append(2)
	elif g % 2 == 1:
		r.append(1)
	else:
		r.append(0)
for i in r:
	print(i)


t = int(input())
for i in range(t):
	n = int(input())
	if 2 == n:
		print(2)
		continue
	print(n % 2)


list = []
for i in range(int(input())):
	list.append(int(input()))
for index in list:
	if index == 2:
		print('2')
	elif index % 2 == 0 and index > 2:
		print('0')
	else:
		print('1')


n = int(input())
l = []
for i in range(n):
	a = int(input())
	if a / 2 > 1 and a % 2 == 0:
		l.append(0)
	elif a / 2 == 1:
		l.append(2)
	elif a % 2 == 1:
		l.append(1)
print(*l)


q = int(input())
sp = []
for i in range(q):
	n = int(input())
	if n == 1:
		sp.append(3)
	elif n == 2:
		sp.append(2)
	elif n % 2 == 0:
		sp.append(0)
	else:
		sp.append(1)
for j in range(len(sp)):
	print(sp[j])


a = int(input())
f = 2
for m in range(a):
	q = int(input())
	if q == 2:
		print(f)
	elif q % 2 == 0:
		print(0)
	elif q % 2 != 0:
		print(1)


times = int(input())
for i in range(times):
	n = int(input())
	if n < 4:
		print(str(4 - n))
	elif n % 2 == 0:
		print('0')
	else:
		print('1')


t = int(input())
for z in range(t):
	n = int(input())
	if n == 2:
		print(2)
		continue
	print(n % 2)


n = int(input())
i = []
a = 0
while a < n:
	q = int(input())
	if q == 2:
		i.append(2)
	elif q > 2 and q % 2 == 0:
		i.append(0)
	else:
		i.append(1)
	a += 1
for x in i:
	print(x)


import sys
t = int(input())
n = []
for i in range(t):
	n.append(int(input()))
for m in n:
	count = 0
	while m == 2 or m % 2 != 0:
		m += 1
		count += 1
	print(count)


q = int(input())
for _ in range(q):
	n = int(input())
	if n == 1:
		print(3)
	elif n % 2 == 0 and n != 2:
		print(0)
	else:
		print((n // 2 + 1) * 2 - n)


for _ in range(int(input())):
	cur = int(input())
	if cur < 4:
		print(4 - cur)
	else:
		print(cur % 2)


k = int(input())
for i in range(k):
	a = int(input())
	if a % 2 == 0 and a != 0 and (a != 2):
		print(0)
	elif a == 0:
		print(4)
	elif a == 2:
		print(2)
	else:
		print(1)


q = int(input())
A = []
B = []
for i in range(q):
	A.append(int(input()))
	if A[i] == 1:
		B.append(3)
	elif A[i] == 2:
		B.append(2)
	elif A[i] % 2 == 0:
		B.append(0)
	elif A[i] % 2 != 0:
		B.append(1)
for i in range(0, len(B)):
	print(B[i])


import sys
import math
from math import ceil
import bisect

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def finput():
	return float(input())

def tinput():
	return input().split()

def rinput():
	return map(float, tinput())

def rlinput():
	return list(rinput())

def modst(a, s):
	res = 1
	while s:
		if s % 2:
			res *= a
		a *= a
		s //= 2
	return res

def pro(x):
	if x < 37:
		return (x - 1) // 4
	else:
		return 8 - (x - 37) // 2

def main():
	n = iinput()
	if n >= 3 and n % 2:
		print(1)
	elif n >= 3 and n % 2 == 0:
		print(0)
	elif n == 2:
		print(2)
for i in range(iinput()):
	main()


a = int(input())
A = [] * a
A = [int(input()) for i in range(a)]
for i in range(a):
	count = 0
	if int(A[i]) < 4:
		print(4 - int(A[i]))
	elif int(A[i]) % 2 == 0:
		print(0)
	else:
		print(int(A[i]) // 2 * 2 + 2 - int(A[i]))


n = int(input())
for _ in range(n):
	num = int(input())
	if num % 2 == 0:
		count = 0
	else:
		count = 1
		num = num + 1
	if num == 2:
		count += 2
	print(count)


test = int(input())
for _ in range(test):
	c = int(input())
	if c < 4:
		print(4 - c)
	elif not c % 2:
		print(0)
	else:
		print(1)


from sys import stdin
inp = stdin.readline
t = int(inp().strip())
while t:
	t -= 1
	n = int(inp().strip())
	if n == 2:
		print(2)
	else:
		print(n % 2)


c = int(input())
inputs = []
outputs = []
for i in range(c):
	inputs.append(int(input()))
	if inputs[i] == 2:
		outputs.append(2)
	elif inputs[i] % 2 == 0:
		outputs.append(0)
	elif inputs[i] % 2 == 1:
		outputs.append(1)
for i in range(c):
	print(outputs[i])


import math
q = int(input())
rez = []
for i in range(q):
	m = int(input())
	if m == 2:
		rez.append(2)
	else:
		c = 0
		c = math.ceil(m / 2)
		r = abs(m - 2 * c)
		rez.append(r)
for i in rez:
	print(i)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def pow(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
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

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

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]

def YES():
	print('YES')

def NO():
	print('NO')

def Yes():
	print('Yes')

def No():
	print('No')
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24

class MergeFind:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n

	def find(self, a):
		to_update = []
		while a != self.parent[a]:
			to_update.append(a)
			a = self.parent[a]
		for b in to_update:
			self.parent[b] = a
		return self.parent[a]

	def merge(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a == b:
			return
		self.num_sets -= 1
		self.parent[a] = b
		self.size[b] += self.size[a]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

def solve():
	n = N()
	if n == 2:
		print(2)
		return
	if n % 2 == 0:
		print(0)
	else:
		print(1)
testcase(int(inp()))


n = int(input())
l = []
while n > 0:
	n = n - 1
	x = int(input())
	if x == 2:
		l.append('2')
	elif x % 2 != 0:
		l.append('1')
	else:
		l.append('0')
for i in l:
	print(i)


numqueries = int(input())

def CME(matches):
	if matches < 4:
		return 4 - matches
	if matches % 2 == 1:
		return 1
	elif matches % 2 == 0:
		return 0
for i in range(numqueries):
	print(CME(int(input())))


for _ in range(int(input())):
	n = int(input())
	print(max(4 - n, n % 2))


for _ in range(int(input())):
	n = int(input())
	if n < 4:
		print(4 - n)
	else:
		print(n & 1)


k = int(input())
for _ in range(k):
	n = int(input())
	l = n // 2
	r = n - l
	if l == r:
		a = 0 if l > 1 else 2
		print(a)
	else:
		diff = 1
		if l == 0:
			diff += 2
		print(diff)


q = int(input())
list = []
for i in range(q):
	el = int(input())
	if el > 2:
		if el % 2 != 0:
			el = 1
		else:
			el = 0
	else:
		el = 4 - el
	list.append(el)
for el in list:
	print(el)


import math
n = int(input())
for i in range(n):
	a = int(input())
	if a < 4:
		print(4 - a)
	elif a % 2 == 0:
		print(0)
	else:
		print(1)


q = int(input())
n = []
for item in range(q):
	n.append(int(input()))
for item in n:
	if item == 2:
		print(2)
	elif item % 2 == 0:
		print(0)
	else:
		print(1)


n = int(input())
k = []
for i in range(n):
	k.append(int(input()))
for i in range(n):
	if k[i] % 2 == 0 and k[i] > 3:
		print(0)
	elif k[i] >= 3:
		print(1)
	elif k[i] == 2:
		print(2)


kQ = int(input())
ans = []
for i in range(kQ):
	number = int(input())
	if number <= 4:
		ans.append(4 - number)
	else:
		ans.append(number % 2)
print(*ans, sep='\n')


numQueries = int(input())
queries = []
for i in range(numQueries):
	queries.append(int(input()))
for i in range(len(queries)):
	if queries[i] == 1:
		minAmount = 3
	elif queries[i] == 2:
		minAmount = 4
	elif queries[i] % 2 == 0:
		minAmount = queries[i]
	else:
		minAmount = queries[i] + 1
	print(minAmount - queries[i])


exec(int(input()) * 'n=int(input());n1=n+2;n2=n+1;print(n if n==2 else n%2);')


def foo(n):
	if n & 1:
		return 1
	if n == 2:
		return 2
	else:
		return 0
times = int(input())
for _ in range(times):
	n = int(input())
	print(foo(n))


T = int(input())
results = []
for case in range(1, T + 1):
	n = int(input())
	result = 0
	if n < 4:
		result = 4 - n
	elif n % 2 == 1:
		result = 1
	results.append(result)
for result in results:
	print(result)


q = int(input())
n = []
for i in range(q):
	n.append(int(input()))

def f(a):
	if a % 2 == 0:
		if a == 2:
			return 2
		else:
			return 0
	else:
		return a % 2
for i in range(len(n)):
	print(f(n[i]))


import math
from collections import *
import sys
from functools import reduce

def get_ints():
	return map(int, input().strip().split())

def get_list():
	return list(get_ints())

def get_string():
	return list(input().strip().split())

def printxsp(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')
UGLYMOD = int(1000000000.0) + 7
SEXYMOD = 998244353
MAXN = int(100000.0)
for _testcases_ in range(int(input())):
	n = int(input())
	print(max(4 - n, n & 1))


n = int(input())
lines = []
for i in range(n):
	line = int(input())
	if line:
		lines.append(line)
	else:
		break
faces = 0
var = lines
for i in var:
	if i < 4:
		print('{}'.format(4 - i))
	elif i % 2 == 0:
		print('0')
	else:
		print('1')


q = input()
q = int(q)
for x in range(q):
	n = input()
	n = int(n)
	if n == 2:
		print(2)
		continue
	if n % 2 == 0:
		print(0)
	else:
		e = n // 2
		e = int(e)
		c = e + 1
		c = c * 2
		w = c - n
		print(w)


from math import ceil
k = int(input())
for i in range(k):
	n = int(input())
	if n == 2:
		print(2)
	else:
		a = ceil(n / 2)
		print(a - n // 2)


import math
for i in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
		continue
	sum = n // 2
	if n % 2:
		sum += 1
	print(sum - n // 2)


n = int(input())
z = n
b = '0'
a = []
Q = 0
while n > 0:
	x = int(input())
	if x > 3 and x % 2 == 0:
		a += ['0']
	elif x < 3:
		a += ['2']
	else:
		a += ['1']
	n = n - 1
while Q != z:
	try:
		print(a[Q])
	except Exception as exc:
		print(str(exc))
	Q = Q + 1


for _ in range(int(input())):
	n = int(input())
	print(n % 2 + 2 * (n == 2))


q = int(input())
for t in range(q):
	n = int(input())
	if n == 2:
		print(n)
	else:
		a = n // 2
		b = n - a
		print(b - a)


n = int(input())
arr = []
for i in range(n):
	a = int(input())
	if a < 4:
		arr.append(4 - a)
	else:
		arr.append(a % 2)
for i in range(n):
	print(arr[i])


def solve(n):
	if n == 2:
		return 2
	else:
		return n % 2
a = []
for i in range(int(input())):
	j = int(input())
	a.append(solve(j))
for i in a:
	print(i)


for _ in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
		continue
	print(n & 1)


for i in range(int(input())):
	q = int(input())
	if q == 2:
		print(2)
	elif q % 2 != 0:
		print(1)
	elif q % 2 == 0 and q > 2:
		print(0)


q = int(input())
i = 1
j = 1
list1 = []
for i in range(1, q + 1):
	a = int(input())
	if a > 3:
		list1.append(a % 2)
	else:
		list1.append(4 - a % 4)
	i += 1
for j in list1:
	print(j, sep='\n')


otv = 0
mass = ''
q = int(input())
for i in range(q):
	a = int(input())
	while a < 3:
		a += 1
		otv += 1
	if a % 2 != 0:
		a += 1
		otv += 1
	while a / 2 <= 1:
		a += 1
		otv += 1
	mass = mass + str(otv)
	otv = 0
for i in range(q):
	print(mass[i])


output = []
n = int(input())
for i in range(n):
	matches = int(input())
	if matches < 4:
		output.append(str(4 - matches))
	else:
		output.append(str(matches % 2))
print(' '.join(output))


q = int(input())
n = []
for i in range(q):
	n.append(int(input()))
result = []
for i in n:
	if i >= 4:
		if i % 2 == 0:
			result.append(0)
		else:
			result.append(1)
	else:
		result.append(4 - i)
for i in result:
	print(i)


a = int(input())
arr = []
for i in range(a):
	arr += [int(input())]
for i in arr:
	if i % 2 == 0:
		if i == 2:
			print(2)
		else:
			print(0)
	elif i == 1:
		print(3)
	else:
		print(1)


n = int(input())
a = []
for _ in range(n):
	a += [int(input())]
ans = []
for el in a:
	if el == 1:
		ans += [3]
	elif el == 2:
		ans += [2]
	else:
		x = (el - 2) // 2
		el = el - x - 1
		if x + 1 == el:
			ans += [0]
		else:
			ans += [el - 1 - x]
print(*ans, sep='\n')


def solve(n):
	n_start = n
	(a, b, c) = (0, 0, 0)
	while a == 0 or b == 0 or c == 0:
		if n % 2 == 0:
			c = n // 2
			a = n // 2 // 2
			b = a
			if a == 0 or b == 0 or c == 0:
				n += 1
		else:
			n += 1
			c = n // 2
			a = n // 2 // 2
			b = a
	return n - n_start
inputs = []
for i in range(int(input(''))):
	inputs.append(int(input('')))
for input_ in inputs:
	print(solve(input_))


import math
n = int(input())
for i in range(n):
	temp = int(input())
	if temp == 2:
		print(2)
		continue
	if temp % 2 == 0:
		print(0)
	else:
		print(1)


def buy_match(n):
	answer = 0
	if n == 2:
		answer = 2
	elif n % 2 == 0:
		answer = 0
	else:
		answer = 1
	return answer

def cme_range(arr, length):
	for i in range(length):
		print(buy_match(arr[i]))
arr = []
n = int(input())
for i in range(n):
	item = int(input())
	arr.append(item)
cme_range(arr, n)


n = int(input())
for item in range(n):
	num = int(input())
	if num == 2:
		print(2)
	elif num % 2 == 0:
		print(0)
	else:
		print(1)


def kyc(z):
	if z == 0:
		return 4
	elif z == 1:
		return 3
	elif z == 2:
		return 2
	elif z == 3:
		return 1
	elif z > 4 and z % 2 == 1:
		return 1
	else:
		return 0
a = []
N = int(input())
for i in range(0, N):
	a.append(int(input()))
for i in range(0, N):
	print(kyc(a[i]))


q = int(input())
j = 0
for j in range(q):
	n = int(input())
	i = n
	d = n
	if n % 2 == 0 and n > 3:
		print(0)
	else:
		while d != 0:
			s = n // i
			if (n + s) % 2 == 0 and n + s > 3:
				print(s)
				break
			elif n == 1:
				print(3)
			d -= 1
			i -= 1


import sys
q = int(sys.stdin.readline())
for case in map(int, sys.stdin):
	if case < 4:
		print(str(4 - case))
	elif case % 2 == 1:
		print('1')
	else:
		print('0')


a = int(input())
B = []
for i in range(a):
	b = int(input())
	B.append(b)
for i in B:
	if i == 2:
		print(2)
	elif i == 1:
		print(3)
	elif i == 0:
		print(4)
	elif i % 2 == 0:
		print(0)
	else:
		print(1)


def CME(n):
	if n == 2:
		return 2
	elif n % 2 == 1:
		return 1
	else:
		return 0
queries = int(input())
for i in range(queries):
	n = int(input())
	print(CME(n))


from sys import exit as sys_return
queries = int(input())
while queries != 0:
	queries -= 1
	amount = int(input())
	if amount < 4:
		print(4 - amount)
	else:
		print(amount % 2)


for _ in range(int(input())):
	n = int(input())
	a = n // 2 + n % 2
	b = n // 2
	if n == 2:
		print(2)
	else:
		print(a - b)


n1 = input()
n = int(n1)
for i in range(n):
	k1 = input()
	mat = int(k1)
	if mat == 2:
		print('2')
	elif mat == 3:
		print('1')
	elif mat % 2 == 0:
		print('0')
	else:
		print('1')


def work():
	n = eval(input())
	if n == 2:
		print('2')
		return
	if n % 2 == 1:
		print('1')
	else:
		print('0')
	return

def main():
	m = eval(input())
	while m > 0:
		work()
		m -= 1
	return
main()


N = int(input())
for i in range(N):
	k = int(input())
	if k == 2:
		print(2)
	elif k % 2 == 1:
		print(1)
	else:
		print(0)


q = int(input())
n = []
for a in range(q):
	b = int(input())
	if b == 2:
		n.append('2 ')
	else:
		n.append(['0 ', '1 '][b % 2])
print(' '.join(n))


from sys import stdin
n = int(stdin.readline().rstrip())
for _ in range(n):
	m = int(stdin.readline().rstrip())
	if m < 4:
		print(4 - m)
	else:
		print(m % 2)


import sys
from collections import defaultdict, deque
from math import sqrt

def input():
	return sys.stdin.readline()[:-1]
q = int(input())
for _ in range(q):
	n = int(input())
	if n <= 4:
		print(4 - n)
	else:
		print(n % 2)


n = int(input())
l = []
for i in range(n):
	l.append(int(input()))
for z in l:
	print(4 - z if z < 4 else z % 2)


q = int(input())
i = 0
a = []
while i < q:
	n = int(input())
	a.append(n)
	i = i + 1
for k in range(len(a)):
	if a[k] == 2:
		print(2)
	elif a[k] % 2 == 0 and a[k] != 2:
		print(0)
	else:
		print(1)


num = int(input())
s = []
for i in range(num):
	n = int(input())
	k = 0
	if n % 2 == 1:
		k += 1
		n += 1
	if n // 2 == 1:
		k += 2
	s.append(k)
for i in s:
	print(i)


n = int(input())
lst = []
for i in range(n):
	num = int(input())
	lst.append(num)
for x in lst:
	if x == 2:
		print('2', end=' ')
	else:
		a = x // 2
		c = x - a
		b = c - a
		print(b, end=' ')


def zapr(n):
	if n == 2:
		return 2
	else:
		return n % 2
q = int(input())
for i in range(q):
	print(zapr(int(input())))


n = int(input())
count = []
for x in range(0, n):
	k = int(input())
	if k == 2:
		count.append(2)
	elif k % 2 == 0:
		count.append(0)
	else:
		count.append(1)
for x in count:
	print(x)


N = int(input())
ans = []
for i in range(N):
	n = int(input())
	if n == 2:
		ans.append(2)
		continue
	ans.append(n % 2)
for j in ans:
	print(j)


q = int(input())
ar = []
for _ in range(q):
	ar.append(int(input()))
for i in range(q):
	if ar[i] < 4:
		print(abs(ar[i] - 4))
	elif ar[i] % 2 == 0:
		print(0)
	else:
		print(1)


t = int(input())
while t > 0:
	a = int(input())
	if a == 2:
		print(a)
	elif a % 2 != 0 and a != 2:
		print(1)
	elif a % 2 == 0 and a > 2:
		print(0)
	t -= 1


a = int(input())
s = []
for i in range(a):
	b = int(input())
	s.append(b)
for i in range(a):
	if s[i] == 2:
		print(2)
	elif s[i] % 2 == 0:
		print(0)
	else:
		print(1)


q = int(input())
ns = []
for x in range(q):
	ns.append(int(input()))
for y in ns:
	if y == 2:
		print(2)
	elif y % 2 == 0:
		print(0)
	elif y % 2 == 1:
		print(1)


n = int(input())
i = 0
while i < n:
	a = int(input())
	if a % 2 != 0 and a != 2:
		print(1)
	elif a % 2 == 0 and a != 2:
		print(0)
	elif a == 2:
		print(2)
	i += 1


for t in range(int(input())):
	a = int(input())
	if a == 2:
		print(2)
	elif a % 2 == 0 and a > 2:
		print(0)
	else:
		print(1)


import math
numberOfCases = int(input())
listOfBoughtMathces = []
for i in range(numberOfCases):
	numberofMatches = int(input())
	if numberofMatches < 4:
		boughtMatches = 4 - numberofMatches
	elif numberofMatches % 2 == 0:
		boughtMatches = 0
	else:
		boughtMatches = 1
	listOfBoughtMathces.append(boughtMatches)
print(*listOfBoughtMathces, sep='\n')


num = int(input())
l_ist = []
for x in range(num):
	l_ist.append(int(input()))
for x in l_ist:
	if x < 4:
		print(4 - x)
	else:
		print(x % 2)


data = input()
data = int(data)
ar = []
for i in range(data):
	a = input()
	ar.append(int(a))
for i in range(len(ar)):
	if ar[i] < 4:
		print(4 - ar[i])
	elif ar[i] % 2 != 0:
		print(1)
	else:
		print(0)


nb_test = int(input())
for i in range(0, nb_test):
	n = int(input())
	if n == 2:
		print('2')
	elif n % 2 == 0:
		print('0')
	elif n % 2 != 0:
		print('1')


for i in range(int(input())):
	A = int(input())
	if A < 4:
		print(4 - A)
	elif A % 2 == 0:
		print(0)
	else:
		print(1)


lst = []
n = int(input())
for i in range(0, n):
	tmp = int(input())
	lst.append(tmp)
for i in range(0, n):
	if lst[i] == 2:
		print(2)
	elif lst[i] % 2 == 0:
		print(0)
	else:
		print(1)


q = int(input())
for query in range(q):
	sticks = int(input())
	if sticks < 4:
		print(4 - sticks)
	elif sticks % 2 == 0:
		print(0)
	else:
		print(1)


output = []
for _ in range(int(input())):
	sticks = 0
	n = int(input())
	if n % 2 == 0:
		if n == 2:
			sticks = 2
	else:
		sticks = 1
	output.append(sticks)
for i in output:
	print(i)


t = int(input())
for tt in range(t):
	n = int(input())
	if n == 1:
		print(3)
	elif n == 2:
		print(2)
	else:
		print(n % 2)


q = int(input())
for j in range(q):
	inp = int(input())
	if inp == 1:
		print('3')
	elif inp == 2:
		print('2')
	elif inp % 2 == 0:
		print('0')
	else:
		print('1')


a = int(input())
i = 0
while i < a:
	nb = int(input())
	if nb == 2:
		print('2')
	elif nb % 2 == 0:
		print('0')
	else:
		print('1')
	i = i + 1


inp = int(input())
A = []
for i in range(inp):
	A.append(int(input()))
for i in A:
	out = 0
	if i < 4:
		print(4 - i)
	else:
		print(i % 2)


import math

def main():
	q = int(input())
	for _ in range(q):
		n = int(input())
		if n == 2:
			print(2)
		elif n % 2 == 0:
			print(0)
		else:
			print(1)
main()


q = int(input())
L = []
N = []
for i in range(q):
	L.append(int(input()))
for j in L:
	if j % 2 == 0:
		if j == 2:
			N.append(2)
		else:
			N.append(0)
	else:
		N.append(1)
for i in N:
	print(i)


queries = int(input())
amount_of_matches = []
while queries > 0:
	amount_of_matches.append(int(input()))
	queries -= 1
for matches in amount_of_matches:
	if matches >= 4:
		if matches % 2 == 0:
			print('0')
		else:
			print('1')
	else:
		difference = 4 - matches
		print(difference)


def is_valid(n, a, b, c):
	return a > 0 and b > 0 and (c > 0) and (a + b + c == n) and (a + b == c)

def process(n):
	if n == 2:
		return 2
	return 0 if n % 2 == 0 else 1
data = [int(input()) for _ in range(int(input()))]
result = list(map(lambda el: process(el), data))
print(*result, sep='\n')


x = int(input())
for i in range(x):
	y = int(input())
	if y <= 4:
		print(4 - y)
	elif y % 2 == 0:
		print(0)
	else:
		print(1)


myrange = input()
myrange = int(myrange)
matches = []
for x in range(myrange):
	this_one = input()
	matches.append(int(this_one))
for n in matches:
	print(4 - n if n < 4 else n % 2)


while 1:
	try:
		n = int(input())
	except:
		break
	for i in range(n):
		p = int(input())
		if p < 4:
			print(4 - p)
		elif p & 1:
			print('1')
		else:
			print('0')


test_case = int(input())
needed = 0
while test_case > 0:
	number = int(input())
	if number <= 2:
		needed = abs(4 - number)
	elif number % 2 != 0:
		needed = 1
	else:
		needed = 0
	print(needed)
	test_case = test_case - 1


q = int(input())
if q > 0:
	n = []
	for i in range(q):
		check = bool(1)
		nIn = int(input())
		if not 2 <= nIn <= 10 ** 9:
			check = bool(0)
		n.append(nIn)
	if check:
		buy = []
		for i in range(0, len(n)):
			if n[i] == 2:
				buy.append(2)
			elif n[i] % 2 != 0:
				buy.append(1)
			else:
				buy.append(0)
	for i in range(0, len(buy)):
		print(buy[i])


q = int(input())
while q:
	n = int(input())
	for i in range(n // 2, n + 1):
		h = n - 2 * i
		if h <= 0:
			if i >= 2 and n >= 2:
				print(-1 * h)
				break
			elif h < 0:
				print(-1 * h)
				break
	q -= 1


def solve(inp):
	ans = []
	for i in inp:
		if i == 2:
			ans.append('2')
			continue
		if i % 2 == 0 and i != 2:
			ans.append('0')
			continue
		ans.append('1')
	return '\n'.join(ans)
n = int(input())
inp = []
for i in range(n):
	inp.append(int(input()))
print(solve(inp))


N = int(input())
l = []
for i in range(N):
	n = int(input())
	if n < 4:
		l.append(4 - n)
		continue
	l.append(n % 2)
	c = (n + n % 2) // 2
print(*l, sep='\n')


n = int(input())

def ans(x):
	if x < 4:
		return 4 - x
	if x % 2 != 0:
		return 1
	return 0
for _ in range(n):
	print(ans(int(input())))


q = int(input())

def f(a):
	if a == 1:
		return 3
	elif a == 2:
		return 2
	elif a % 2 != 0:
		return 1
	else:
		return 0
for i in range(q):
	w = int(input())
	print(f(w))


def solve(n):
	if n == 2:
		return 2
	if n % 2 == 0:
		return 0
	else:
		return 1
t = int(input())
for i in range(t):
	n = int(input())
	print(solve(n))


def solve(n):
	if n <= 2:
		return 4 - n
	elif n % 2 != 0:
		return 1
	else:
		return 0
q = int(input())
for i in range(q):
	n = int(input())
	y = solve(n)
	print(y)


def cme(n):
	if n < 4:
		return 4 - n
	elif n >= 4:
		if n % 2 == 0:
			return 0
		elif n % 2 == 1:
			return 1
queries = int(input())
for q in range(queries):
	N = int(input())
	res = cme(N)
	print(res)


from collections import deque, Counter
import array
from itertools import combinations, permutations
from math import sqrt

def read_int():
	return int(input().strip())

def read_int_array():
	return [int(i) for i in input().strip().split(' ')]
tests = read_int()
for test in range(tests):
	n = read_int()
	if n == 2:
		print(2)
	else:
		print(1 if n % 2 == 1 else 0)


def KYC(n):
	if n == 2:
		return 2
	elif n % 2 == 0:
		return 0
	else:
		return 1

def main():
	m = int(input())
	for i in range(m):
		n = int(input())
		print(KYC(n))
	pass
main()


try:
	t = int(input())
	while t:
		n = int(input())
		if n - 2 == 0:
			print('2')
		else:
			n = n - 2
			print(n % 2)
		t -= 1
except:
	pass


a = int(input())
b = 0
while b < a:
	c = int(input())
	d = c
	while c < 4 or c % 2 == 1:
		c += 1
	b += 1
	print(c - d)


x = int(input(''))
list1 = []
for i in range(0, x):
	a = int(input(''))
	if a < 4:
		list1.append(4 - a)
	elif a % 2 == 0:
		list1.append(0)
	else:
		list1.append(1)
for i in range(0, len(list1)):
	print(list1[i])


l = int(input())
for _ in range(l):
	n = int(input())
	if n > 2:
		if n % 2 == 0:
			print('0')
		else:
			print('1')
	else:
		print(4 - n)


def do():
	if n == 1:
		print(3)
		return
	if n == 2:
		print(2)
		return
	if n & 1 == 1:
		print(1)
	else:
		print(0)
q = int(input())
for _ in range(q):
	n = int(input())
	do()


q = int(input())
for i in range(q):
	n = int(input())
	for w in range(10):
		if n % 4 + w == 0 or ((n + w) // 2 == (n + w) / 2 and n + w >= 4):
			print(w)
			break
		else:
			w = w + 1


def dkwpwn(num):
	if num < 4:
		return 4 - num
	return 1 if num & 1 else 0
q = int(input())
for _ in range(q):
	num = int(input())
	print(dkwpwn(num))


z = int(input())
for i in range(z):
	a = int(input())
	if a >= 4:
		print(a % 2)
	else:
		print(4 - a)


T = int(input())
for z in range(T):
	N = int(input())
	if N < 4:
		print(4 - N)
	elif N % 2 == 0:
		print(0)
	else:
		print(1)


from math import *
for _ in ' ' * int(input()):
	n = int(input())
	if n == 1:
		print(2)
		continue
	elif n == 2:
		print(2)
		continue
	elif n % 2 == 0:
		print(0)
	else:
		print(1)


def solve(query):
	while query % 2 != 0:
		query += 1
	return query
queries_count = int(input())
while queries_count > 0:
	query = int(input())
	if query == 2:
		print(query)
	else:
		print(solve(query) - query)
	queries_count -= 1


q = int(input())
for i in range(q):
	w = int(input())
	if w < 3:
		print(4 - w)
	else:
		print(w % 2)


queries = int(input())
for i in range(queries):
	matches = int(input())
	if matches == 2:
		print(2)
		continue
	if matches % 2 == 0:
		print(0)
	else:
		print(1)


z = input
for _ in range(int(z())):
	n = int(z())
	print(2 if n == 2 else n % 2)


def solve(n):
	if n == 2:
		return 2
	if n % 2 != 0:
		return 1
	return 0
for x in range(int(input())):
	n = int(input())
	print(solve(n))


n = int(input())
for i in range(n):
	x = int(input())
	if x < 4:
		print(4 - x)
	elif x % 2 == 1:
		print(1)
	elif x % 2 == 0:
		print(0)


for c in '0' * int(input()):
	n = int(input())
	if n == 2:
		print(2)
	elif n % 2 == 0:
		print(0)
	else:
		print(1)


import math

def f():
	n = int(input())
	for _ in range(n):
		min_required = 4
		a = int(input())
		if a <= 4:
			print(4 - a)
		else:
			print('0' if a % 2 == 0 else '1')
f()


n = int(input())
for i in range(n):
	kus = int(input())
	if kus == 1:
		print(3)
		continue
	elif kus == 2:
		print(2)
		continue
	ans = 0
	while True:
		if (kus - 1) % 2 == 1:
			break
		ans += 1
		kus += 1
	print(ans)


s = 0
for i in range(int(input())):
	d = int(input())
	print(d % 2 if d != 2 else 2)


def solve():
	q = int(input())
	ans = ''
	for i in range(q):
		n = int(input())
		if n == 2:
			ans += '2\n'
		elif n % 2 == 0:
			ans += '0\n'
		else:
			ans += '1\n'
	print(ans)
solve()


a = int(input())
s = []
for i in range(a):
	s.append(input())
for c in s:
	c = int(c)
	if c != 2 and c % 2 == 0:
		print(0)
	elif c < 4:
		print(4 - c)
	else:
		print(1)


def cme(n):
	if n <= 2:
		return 4 - n
	else:
		return n % 2
q = int(input())
for _ in range(q):
	n = int(input())
	print(cme(n))


q = int(input())
for i in range(q):
	n = int(input())
	if n == 2:
		print('2', end=' ')
	if n >= 3:
		if n % 2 == 0:
			print('0', end=' ')
		else:
			print('1', end=' ')


for i in range(int(input())):
	mamad = int(input())
	print(2 if mamad == 2 else mamad % 2)


result = ''
for i in range(0, int(input())):
	k = int(input())
	if k >= 4:
		if k % 2 == 0:
			result += '0\n'
		else:
			result += '1\n'
	else:
		result += str(4 - k) + '\n'
print(result)


q = int(input())

def answer(number):
	if number > 2:
		if number % 2 == 0:
			return 0
		else:
			return 1
	elif number == 2:
		return 2
	elif number == 1:
		return 3
	elif number == 0:
		return 4
for i in range(q):
	print(answer(int(input())))


import sys
data = [int(ent.split()[0]) for ent in sys.stdin.readlines()]
for n in data[1:]:
	if n % 2 == 1 and n != 1:
		sys.stdout.write(str(1) + '\n')
	elif n % 2 == 0 and n != 2:
		sys.stdout.write(str(0) + '\n')
	else:
		sys.stdout.write(str(2) + '\n')


import math
q = int(input())
x = 0
for i in range(q):
	n = int(input())
	if n == 2:
		print(2)
	elif n % 2 == 0:
		print(0)
	else:
		x = math.ceil(n / 2)
		print(x - (n - x))


a = int(input())
answer = []
for i in range(a):
	b = int(input())
	if b == 2:
		answer.append(2)
	else:
		answer.append(b % 2)
for i in answer:
	print(i)


t = int(input())
i = 0
a = []
while i < t:
	n = int(input())
	i += 1
	s = 0
	if n // 2 < 2:
		s += 4 - n
		n = 4
	s += n % 2
	a.append(s)
i = 0
while i < t:
	print(a[i])
	i += 1


def no_matches(n):
	if n == 1:
		return 3
	elif n == 2:
		return 2
	elif n % 2 == 0:
		return 0
	else:
		return 1
for _ in range(int(input())):
	print(no_matches(int(input())))


import array, bisect, collections, copy, fractions, functools, heapq, itertools, math, random, re, string, sys, time, os, timeit
sys.setrecursionlimit(10000000)
inf = float('inf')

def li():
	return [int(x) for x in sys.stdin.readline().split()]

def li_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def lf():
	return [float(x) for x in sys.stdin.readline().split()]

def ls():
	return sys.stdin.readline().split()

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

def float_inp():
	return float(sys.stdin.readline())

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

def pf(s):
	return print(s, flush=True)

def main():
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
	q = int_inp()
	ans = []
	for _ in range(q):
		c = int_inp()
		if c >= 4 and c % 2 == 0:
			ans.append('0')
		elif c >= 4:
			ans.append('1')
		else:
			ans.append(str(4 - c))
	if os.path.exists('output.txt'):
		sys.stdout = open('output.txt', 'w')
	print('\n'.join(ans))
main()


(n, x) = (int(input()), [])
for i in range(n):
	x.append(int(input()))
for i in x:
	if i <= 3:
		print(4 - i)
	else:
		print(i % 2)


test = int(input())
z = [int(input()) for x in range(test)]
for total_stick in z:
	if total_stick == 2:
		print(2)
	elif total_stick % 2 != 0:
		print(1)
	else:
		print(0)


n = int(input())
o = []
for i in range(n):
	x = int(input())
	if x == 1:
		o.append(3)
	elif x == 2:
		o.append(2)
	elif x % 2 == 0:
		o.append(0)
	else:
		o.append(1)
for l in o:
	print(l)


q = int(input())
for i in range(q):
	n = int(input())
	amount = 0
	if n % 2:
		amount += 1
		n += 1
	if n // 2 <= 1:
		amount += 2
	print(amount)


exec(int(input()) * 'n=int(input());print(n if n==2 else n%2);')


num = int(input())

def cme(num):
	for x in range(num):
		n = int(input())
		if n == 2:
			print(2)
		elif n % 2 == 1:
			print(1)
		else:
			print(0)
cme(num)


a = []
n = int(input())
for i in range(n):
	new_element = int(input())
	a.append(new_element)
for i in range(n):
	if a[i] >= 4 and a[i] % 2 == 0:
		print(0)
	if a[i] >= 4 and a[i] % 2 == 1:
		print(1)
	if a[i] < 4:
		f = 4 - a[i]
		print(f)


K = int(input())
for k in range(0, K):
	s = int(input())
	if s == 2:
		print(2)
	elif s % 2 == 0:
		print(0)
	else:
		print(1)


q = int(input())
answer = [None] * q
for i in range(q):
	n = int(input())
	if n == 2:
		answer[i] = 2
	elif n % 2 == 0:
		answer[i] = 0
	else:
		answer[i] = 1
print(*answer, sep=' ')


n = [int(input()) for i in range(int(input()))]
for j in range(len(n)):
	if n[j] >= 4 and n[j] % 2 == 0:
		print(0, sep='/n')
	elif n[j] == 2:
		print(2, sep='/n')
	else:
		print(1, sep='/n')


import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue

class Scanner:

	@staticmethod
	def int():
		return int(sys.stdin.readline().rstrip())

	@staticmethod
	def string():
		return sys.stdin.readline().rstrip()

	@staticmethod
	def map_int():
		return [int(x) for x in Scanner.string().split()]

	@staticmethod
	def string_list(n):
		return [input() for i in range(n)]

	@staticmethod
	def int_list_list(n):
		return [Scanner.map_int() for i in range(n)]

	@staticmethod
	def int_cols_list(n):
		return [int(input()) for i in range(n)]

class Math:

	@staticmethod
	def gcd(a, b):
		if b == 0:
			return a
		return Math.gcd(b, a % b)

	@staticmethod
	def lcm(a, b):
		return a * b // Math.gcd(a, b)

	@staticmethod
	def divisor(n):
		res = []
		i = 1
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				res.append(i)
				if i != n // i:
					res.append(n // i)
		return res

	@staticmethod
	def round_up(a, b):
		return -(-a // b)

	@staticmethod
	def is_prime(n):
		if n < 2:
			return False
		if n == 2:
			return True
		if n % 2 == 0:
			return False
		d = int(n ** 0.5) + 1
		for i in range(3, d + 1, 2):
			if n % i == 0:
				return False
		return True

class PriorityQueue:

	def __init__(self, l=[]):
		self.q = l
		heapq.heapify(self.q)
		return

	def push(self, n):
		heapq.heappush(self.q, n)
		return

	def pop(self):
		return heapq.heappop(self.q)
MOD = int(1000000000.0) + 7
INF = int(1000000000000000.0)

def main():
	Q = Scanner.int()
	for _ in range(Q):
		n = Scanner.int()
		if n < 4:
			print(4 - n)
		else:
			print(0 if n % 2 == 0 else 1)
main()


def minim(n):
	r = 0
	if n % 2 == 0 and n >= 4:
		r = 0
	else:
		n += 1
		r += 1
		while n % 2 != 0:
			n += 1
			r += 1
	return r
q = int(input())
for i in range(q):
	n = int(input())
	print(minim(n))


q = int(input())
lst = []
for i in range(q):
	lst.append(int(input()))
for i in lst:
	if i >= 4:
		print(i % 2)
	else:
		print(4 - i)


for i in range(int(input())):
	val = int(input())
	if val == 2:
		print('2')
		continue
	elif val % 2 == 0:
		print('0')
		continue
	else:
		left = val / 2
		right = val - left
		left -= 0.5
		right -= 0.5
		ost = val - left * 2
		left += ost
		print(int(left - right))


a = int(input())
no_of_lines = a
lines = ''
for i in range(a):
	lines += input() + '\n'
b = lines.split()
c = int(0)
while a - c > 0:
	c = c + 1
	if int(b[c - 1]) == 2:
		print('2')
	elif int(b[c - 1]) % 2 == 1:
		print('1')
	else:
		print('0')


import math
for _ in range(int(input())):
	n = int(input())
	if n == 2:
		print(2)
	elif n & 1:
		print(1)
	else:
		print(0)


def answer(n):
	if n < 4:
		return 4 - n
	if n % 2 == 0:
		return 0
	return 1
for i in range(int(input())):
	print(answer(int(input())))


n = int(input())
i = 0
ans = []
while i < n:
	q = int(input())
	if q == 2:
		ans.append(2)
	elif q == 1:
		ans.append(3)
	elif q % 2 == 1:
		ans.append(1)
	else:
		ans.append(0)
	i += 1
for i in ans:
	print(i)


n = int(input())
m = []
for i in range(n):
	j = int(input())
	if j < 4:
		m.append(4 - j)
	else:
		m.append(j % 2)
print(*m, sep='\n', end='')


q = int(input())
for R in range(q):
	n = int(input())
	if n == 2:
		print(2)
	else:
		print(n % 2)


for _ in range(int(input())):
	num = int(input())
	if num % 2 == 0 and num // 2 != 1:
		print(0)
	elif num % 2 == 0 and num // 2 == 1:
		print(2)
	else:
		print(1)


numbers = []
for i in range(int(input())):
	numbers.append(int(input()))
for n in numbers:
	if n == 0:
		print(3)
	elif n == 1:
		print(2)
	elif n == 2:
		print(2)
	else:
		print(n % 2)


t = int(input())
while t:
	n = int(input())
	global ans
	if n > 4:
		ans = n % 2
	else:
		ans = 4 - n
	print(ans)
	t -= 1


t = int(input())
a = []
for i in range(t):
	b = int(input())
	if b % 2 == 0:
		if b == 2:
			a.append(2)
		else:
			a.append(0)
	else:
		d = b // 2 + b % 2
		c = b - d
		a.append(d - c)
for i in a:
	print(i)


q = int(input())
for i in range(0, q):
	n = int(input())
	if n != 2:
		ai = n // 2 - 1
		bi = 1
		ci = n // 2
		af = n / 2 - 1
		bf = 0
		cf = n / 2 - 1
		res = af + bf + cf
		if ai + bi == ci:
			print(int(res % 2))
		else:
			print(int(ci - bi - ai - res))
	else:
		print(2)


a = int(input())
for i in range(a):
	z = int(input())
	if z == 2:
		print(2)
	elif z % 2 == 0:
		print(0)
	elif z % 2 == 1:
		print(1)


strok = int(input())
for i in range(strok):
	vvod = int(input())
	if vvod == 1:
		print(2)
	elif vvod == 2:
		print(2)
	elif vvod % 2 == 0:
		print(0)
	elif vvod % 2 == 1:
		print(1)


N = []
q = int(input())
while q > 0:
	n = int(input())
	N.append(n)
	q -= 1
for i in N:
	if i < 4:
		i = 4 - i
		print(i)
	elif i % 2 == 1:
		print('1')
	else:
		print('0')


import math
t = int(input())
for __ in range(t):
	n = int(input())
	print(4 - n) if n <= 3 else print(n % 2)


def chek(a):
	pass
for i in range(int(input())):
	n = int(input())
	k = 0
	if n == 2:
		k = 2
	elif n == 1:
		k = 3
	elif n % 2 != 0:
		n += 1
		k += 1
	print(k)


t = int(input())
s = []
for kng in range(0, t):
	n = int(input())
	if n == 2:
		s.append(2)
	elif n % 2 == 1:
		s.append(1)
	else:
		s.append(0)
for i in s:
	print(i)


n = int(input())
s = []
for i in range(n):
	p = int(input())
	s.append(p)
for j in s:
	if j == 2:
		print(2)
	elif j % 2 == 0:
		print(0)
	else:
		print(1)


case = int(input())
for caseNum in range(0, case):
	n = int(input())
	if n == 2:
		print(2)
	elif n % 2:
		print(1)
	else:
		print(0)


q = int(input())
for i in range(q):
	m = int(input())
	if m <= 4:
		print(4 - m)
	else:
		print(m % 2)


inp = input
li = list
iinp = lambda : int(inp())
ent = lambda : map(int, inp().split())
lient = lambda : li(ent())
q = iinp()
res = []
for i in range(q):
	c = iinp()
	if c == 2:
		res.append(2)
	else:
		c -= c // 2 * 2
		res.append(c)
for i in res:
	print(i)


i = int(input())
lot = []
for _ in range(i):
	a = int(input())
	if a < 4:
		lot.append(4 - a)
	elif a % 2 != 0:
		lot.append(1)
	else:
		lot.append(0)
for i in lot:
	print(i)


q = int(input())
Ans = []
for i in range(q):
	a = int(input())
	if a < 4:
		Ans.append(4 - a)
	else:
		Ans.append(a % 2)
for i in range(len(Ans)):
	print(Ans[i])


x = int(input())
s = []
for i in range(x):
	s.append(int(input()))
for l in range(x):
	if s[l] != 2:
		if s[l] % 2 == 0:
			print(0)
		else:
			print(1)
	elif s[l] == 2:
		print(2)


q = int(input())
for i in range(q):
	n = int(input())
	if n < 4:
		print(4 - n)
	else:
		a = n // 2
		b = n - a
		print(abs(a - b))


col_naborov = int(input())
col_spichek = []
otveti = []
for i in range(col_naborov):
	q = int(input())
	col_spichek.append(q)
for i in range(col_naborov):
	col = col_spichek[i]
	if col != 2:
		if col % 2 == 1:
			col = 1
		if col % 2 == 0:
			col = 0
	otveti.append(col)
for i in range(col_naborov):
	q = otveti[i]
	print(q)


a = int(input())
if 1 <= a <= 100:
	for i in range(a):
		b = int(input())
		if 2 <= b <= 10 ** 9:
			if b != 2:
				count = b % 2
				print(count)
			else:
				print(2)


I = input
for i in range(int(I())):
	n = int(I())
	print(max(4 - n, n % 2))


t = int(input())
for i in range(t):
	r = int(input())
	if r >= 3:
		if r % 2:
			print(1)
		else:
			print(0)
	elif r == 2:
		print(2)
	elif r == 1:
		print(3)


inp = int(input())
spich = []
slog_1 = 0
slog_2 = 0
sum = 0
schet = 0
sh = 0
while inp > 0:
	inp -= 1
	a = int(input())
	spich.append(a)
for i in spich:
	schet = i
	sh = i
	if sh < 4:
		print(4 - sh)
		continue
	elif sh % 2 == 0:
		print(0)
	else:
		print(1)


q = int(input())
m = []
for i in range(q):
	num = int(input())
	l = 1
	y = 0
	while l == 1:
		if num % 2 == 0 and num // 2 - 1 != 0:
			m.append(y)
			l = 0
		else:
			num += 1
			y += 1
for i in range(len(m)):
	print(m[i])


t = int(input())
i = 0
while i < t:
	n = int(input())
	if n < 4:
		print(4 - n)
	else:
		s = n
		while s % 2 != 0:
			s += 1
		print(s - n)
	i += 1


n = []
for i in range(int(input())):
	k = 0
	a = int(input())
	if a % 2 == 1:
		k += 1
	if a == 2:
		k += 2
	n.append(k)
print('\n'.join(map(str, n)))


q = int(input())
answ = []
for i in range(q):
	x = int(input())
	if x % 2:
		answ.append(1)
	elif x < 3:
		answ.append(2)
	else:
		answ.append(0)
for a in answ:
	print(a)


T = int(input())
while T > 0:
	n = int(input())
	if n == 2:
		print(2)
	elif n % 2 == 0:
		print(0)
	else:
		print(1)
	T -= 1


q = int(input())
mass = []
for i in range(q):
	n = int(input())
	if n == 2:
		mass.append(2)
		continue
	if n % 2 == 1:
		mass.append(1)
		continue
	mass.append(0)
for i in mass:
	print(i)


cant = int(input())
e = 0
t = []
for i in range(cant):
	d = int(input())
	while (d + e) % 2 > 0 or d + e <= 3:
		e = e + 1
	t.append(e)
	e = 0
for n in range(len(t)):
	print(t[n])


loo = int(input())
for i in range(loo):
	getInput = int(input())
	if getInput == 2:
		print(2)
	elif getInput % 2 == 0:
		print(0)
	else:
		print(1)


q = int(input())
if q < 2 or q > 100:
	exit()
n = []
for x in range(q):
	n.append(int(input()))
	if n[x] < 2 or n[x] > 10 ** 9:
		exit()
for i in n:
	if i % 2 == 0 and i >= 4:
		print(0)
	else:
		j = 1
		while True:
			k = i
			k += j
			if k % 2 == 0 and k >= 4:
				print(j)
				break
			else:
				j += 1


q = int(input())
for items in range(q):
	n = int(input())
	if n == 2:
		print(2)
	else:
		print(n % 2)


k = int(input())
A = []
B = []
for i in range(k):
	A.append(int(input()))
	if A[i] == 2:
		B.append(2)
	elif A[i] % 2 == 0:
		B.append(0)
	else:
		B.append(1)
for i in range(0, len(B)):
	print(B[i])


import sys
import math

def solve(query):
	n = query
	if n <= 4:
		return 4 - n
	elif n % 2 == 0:
		return 0
	else:
		return 1
q = int(input())
query = []
ans = []
for i in range(q):
	query.append(int(input()))
	ans.append(solve(query[i]))
for i in range(q):
	print(ans[i])


import math
import itertools
from sys import stdin
from functools import reduce
from collections import deque
from sys import setrecursionlimit
from collections import defaultdict
import heapq
input = stdin.readline

def I():
	return int(input())

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

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

def LIN(N):
	return [list(map(int, input().split())) for _ in range(N)]

def solve():
	n = I()
	if n == 2:
		print(2)
	elif n % 2 == 0:
		print(0)
	else:
		print(1)

def main():
	t = 1
	t = I()
	for i in range(1, t + 1):
		solve()
main()


q = int(input())
ls = []
for i in range(q):
	n = int(input())
	if n % 2 != 0:
		ls.append(1)
	elif n == 2:
		ls.append(2)
	else:
		ls.append(0)
for c in ls:
	print(c)


t = int(input())
num = list()
for j in range(t):
	num.append(int(input()))
for j in range(t):
	if num[j] == 2:
		print(2)
	elif num[j] % 2 == 1:
		print(1)
	else:
		print(0)


q = int(input())
for i in range(q):
	n = int(input())
	if n == 0:
		print(4)
	elif n == 1:
		print(3)
	elif n == 2:
		print(2)
	else:
		need = 0
		while n % 2 != 0:
			n += 1
			need += 1
			break
		print(need)


q = int(input())
for _ in range(q):
	inp = int(input())
	if inp == 1 or inp == 2:
		print(2)
	elif inp % 2 == 0:
		print(0)
	else:
		print(1)


num_query = int(input(''))
list_query = [int(input('')) for i in range(num_query)]
answer_list = []
for i in list_query:
	if i == 1:
		answer_list.append(3)
	elif i == 2:
		answer_list.append(2)
	elif i % 2 == 0:
		answer_list.append(0)
	elif i % 2 != 0:
		answer_list.append(1)
for i in answer_list:
	print(i)


CME = 0
for i in range(int(input())):
	_ = int(input())
	if _ == 2:
		CME = 2
	else:
		CME = 0
	print(CME if _ % 2 == 0 else 1)


output = []
n = int(input())
for i in range(n):
	matches = int(input())
	if matches >= 4 and matches % 2 == 0:
		output.append('0')
	elif matches < 4:
		output.append(str(4 - matches))
	else:
		output.append('1')
print(' '.join(output))


number = int(input())
n = 0
result = []
data = []
while number > n:
	data.append(int(input()))
	if data[n] > 4:
		if data[n] % 2 == 0:
			result.append(0)
		else:
			result.append(1)
	else:
		result.append(4 - data[n])
	n += 1
n = 0
while number > n:
	print(result[n])
	n += 1


q = int(input())
o = []
for i in range(q):
	n = int(input())
	if n % 2 == 0 and n >= 4:
		o.append(0)
	elif n < 4:
		o.append(4 - n)
	else:
		o.append(1)
print(*o, sep='\n')


array = [int(input()) for i in range(int(input()))]
for elem in array:
	if elem == 2:
		print(2)
	else:
		print(elem % 2)


import sys
input = sys.stdin.readline
CME = 0
for i in range(int(input())):
	_ = int(input())
	if _ == 2:
		CME = 2
	else:
		CME = 0
	print(CME if _ % 2 == 0 else 1)


for i in range(int(input())):
	spich = int(input())
	if spich == 2:
		print(2)
	elif spich % 2 == 0:
		print(0)
	elif spich % 2 != 0:
		print(1)


t = int(input())
out = []
for u in range(t):
	a = int(input())
	if a == 2:
		out.append(2)
	elif a % 2 != 0:
		out.append(1)
	else:
		out.append(0)
for i in out:
	print(i)


import math

def okr_up(a):
	q = math.floor(a)
	if q != a:
		return q + 1
	else:
		return q

def func(n):
	if n == 4:
		return 0
	elif n < 4:
		return int(4 - n)
	else:
		w1 = math.floor(n / 4)
		w2 = okr_up(n / 4)
		w3 = int(n - w1 - w2)
		m = [w1, w2, w3]
		m.sort()
		a = m[0]
		b = m[1]
		c = m[2]
		if a + b == c:
			return 0
		else:
			return abs(a + b - c)
q = int(input())
for i in range(q):
	n = float(input())
	print(func(n))


n = int(input())
I = []
for i in range(n):
	k = int(input())
	I.append(k)

def CME(l):
	if l % 2 == 0:
		if l == 2:
			return l
		else:
			return 0
	else:
		return 1
for i in range(n):
	k = CME(I[i])
	print(k)


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

def ss():
	return [x for x in input()]

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

def mi():
	return map(int, input().split())
a = ii()
for i in range(a):
	x = ii()
	if x < 5:
		print(4 - x)
	else:
		print(x % 2)


q = int(input())
for x in range(q):
	count = 0
	n = int(input())
	while True:
		if n % 2 != 0:
			n += 1
			count += 1
			continue
		if n / 2 < 2:
			n += 1
			count += 1
			continue
		else:
			print(count)
			break


import time

def createEquation(matches):
	matchesNeeded = []
	for qMat in matches:
		if qMat <= 4:
			matchesNeeded.append(4 - qMat)
		else:
			calc = qMat % 2
			matchesNeeded.append(calc)
	return matchesNeeded

def solve():
	queries = int(input())
	matches = []
	for x in range(queries):
		matches.append(int(input()))
	rMatches = createEquation(matches)
	for y in rMatches:
		print(y)
solve()


n = int(input())
list01 = []
for i in range(n):
	k = int(input())
	list01.append(k)
for j in list01:
	if j % 2 == 0:
		if j == 2:
			print('2')
		else:
			print('0')
	else:
		print('1')


t = int(input())
for i in range(t):
	k = int(input())
	if k == 2:
		print(2)
	else:
		print(k % 2)


q = int(input())
for i in range(q):
	n = int(input())
	if n < 4:
		print(4 - n)
	else:
		a = n // 4
		b = n // 4
		c = n // 2
		while a + b != c:
			if a + b > c:
				n += 1
				c += 1
			else:
				a += 0.5
				b += 0.5
		print(int(n - (a + b + c)))


for i in range(int(input())):
	f = int(input())
	if f < 5:
		print(4 - f)
	elif f % 2 == 0:
		print(0)
	else:
		print(1)


i = int(input())
while i > 0:
	n = int(input())
	k = 0
	if n % 2 != 0:
		k += 1
	if n == 1:
		k = 3
	elif n == 2:
		k = 2
	print(k)
	i -= 1


n = int(input())
lista = [int(input()) for i in range(n)]
for j in lista:
	if j == 2:
		print(2)
	elif j % 2 == 0 and j > 2:
		print(0)
	else:
		print(1)


x = int(input())
for i in range(x):
	m = int(input())
	if m == 1:
		print(3)
	elif m == 2:
		print(2)
	elif m % 2 != 0:
		print(1)
	elif m % 2 == 0:
		print(0)


import math

def solve(test):
	n = int(input())
	ans = 0
	if n < 4:
		ans = 4 - n
	elif n % 2 > 0:
		ans = 1
	print(ans)
t = int(input())
for _ in range(t):
	solve(_ + 1)


q = int(input())
A = []
B = []
for i in range(q):
	temp = int(input())
	A.append(temp)
for i in range(q):
	if A[i] < 3:
		if A[i] == 2:
			B.append(4 - A[i])
	else:
		ost = A[i] % 2
		B.append(ost)
for i in range(q):
	print(B[i])


N = int(input())
arr = []

def kyc(x):
	if x <= 2:
		return 2
	elif x % 2 == 0:
		return 0
	else:
		return 1
for i in range(N):
	arr.append(str(kyc(int(input()))))
print('\n'.join(arr))


def kolv(kus, r):
	if kus[r] >= 4 and kus[r] % 2 == 0:
		return 0
	elif kus[r] < 4:
		return 4 - kus[r]
	else:
		return 1
n = int(input())
kus = list()
for i in range(1, n + 1):
	r = int(input())
	kus.append(r)
for i in range(0, n):
	print(kolv(kus, i))


q = int(input())
cuslist = []
for i in range(q):
	x = int(input())
	cuslist.append(x)
for cus in cuslist:
	if cus == 2:
		print(2)
	else:
		print(cus % 2)


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

def num():
	return int(input())
from itertools import repeat
q = num()
for _ in repeat(None, q):
	n = num()
	if n < 4:
		print(4 - n)
	else:
		print(n % 2)


n = int(input())
li = []
for i in range(n):
	x = int(input())
	li.append(x)
for i in li:
	if i == 2:
		print(2)
	elif i > 2 and i % 2 == 1:
		print(1)
	elif i > 2 and i % 2 == 0:
		print(0)


T = int(input())
ans = ''
for t in range(T):
	n = int(input())
	if n < 4:
		ans += str(4 - n) + '\n'
	else:
		ans += '0\n' if n % 2 == 0 else '1\n'
print(ans, flush=True)


n = int(input())
for i in range(n):
	q = int(input())
	if q >= 3:
		if q % 2 == 0:
			rhs = q // 2
		else:
			rhs = q // 2 + 1
	else:
		rhs = q
	lhs = rhs - (q - rhs)
	print(lhs)


q = int(input())
for i in range(q):
	n = int(input())
	ss = n // 2
	ans = n - ss
	if ss == 1 and ss == ans:
		print(2)
	elif ss == ans:
		print(0)
	elif ss > ans:
		print(ss - ans)
	else:
		print(ans - ss)


q = int(input())
out = []
for i in range(q):
	n = int(input())
	if n == 2:
		out.append(2)
	elif n % 2 == 1:
		out.append(1)
	else:
		out.append(0)
for o in out:
	print(o)


a = int(input())
b = []
for i in range(a):
	b.append(int(input()))
f = [0 for i in range(len(b))]
for i in range(len(b)):
	if b[i] < 4:
		f[i] = 4 - b[i]
	elif b[i] % 2 == 0:
		f[i] = 0
	elif b[i] % 2 != 0:
		f[i] = 1
for i in f:
	print(str(i))


q = int(input())
out = []
for i in range(q):
	n = int(input())
	if n == 2:
		out.append(2)
	elif n % 2 == 1 and n >= 3:
		out.append(1)
	elif n % 2 == 0 and n >= 4:
		out.append(0)
print('\n'.join([str(i) for i in out]))


s = []
for i in range(int(input())):
	s.append(int(input()))
for e in s:
	if e <= 4:
		print(4 - e)
	else:
		print(e % 2)


zapr = int(input())
for i in range(zapr):
	kol_vo = int(input())
	if kol_vo == 2:
		print('2')
	elif kol_vo % 2 == 1:
		print(1)
	elif kol_vo == 0:
		print(4)
	else:
		print(0)


num_q = int(input())
inps = []
for i in range(num_q):
	inps.append(int(input()))
for i in inps:
	if i <= 2:
		print(4 - i)
	elif i % 2 == 0:
		print('0')
	else:
		print('1')


Q = int(input())
for q in range(Q):
	n = int(input())
	if n == 2:
		ans = 2
	elif n % 2 == 1:
		ans = 1
	else:
		ans = 0
	print(ans)


a = int(input())
for i in range(a):
	n = int(input())
	n -= 2
	o = 0
	if n == 0:
		o += 2
	if n % 2 == 0:
		print(0 + o)
	else:
		print(1 + o)


q = int(input())
for i in range(q):
	ch = int(input())
	if ch == 2:
		print(2)
	else:
		print(ch % 2)


t = int(input())
m = 0
while m < t:
	n = int(input())
	if n < 4:
		print(4 - n)
	elif n % 2 == 0:
		print(0)
	else:
		print(1)
	m = m + 1


nvvv = int(input())
for vvv in range(nvvv):
	n = int(input())
	if n == 1:
		print(3)
	elif n == 2:
		print(2)
	elif n % 2 != 0:
		print(1)
	else:
		print(0)


def main():
	n = int(input())
	if n == 2:
		return 2
	elif n / 2 == n // 2:
		return 0
	else:
		return n - 2 * (n // 2)
t = int(input())
for i in range(t):
	print(main())


import math
q = int(input())
for i in range(q):
	n = int(input())
	if n <= 4:
		print(4 - n)
	else:
		print(math.ceil(n / 2) * 2 - n)


for io in range(int(input())):
	n = int(input())
	if n <= 3:
		print(4 - n)
	elif n % 2 == 1:
		print('1')
	else:
		print('0')


def answer():
	n = int(input())
	while n:
		a = int(input())
		if a == 1:
			print(3)
		elif a == 2:
			print(2)
		elif a % 2:
			print(1)
		else:
			print(0)
		n -= 1
answer()


q = int(input())
i1 = q
n = []
while i1 >= 1:
	n.append(int(input()))
	i1 -= 1
for i2 in range(q):
	if n[i2] == 2:
		print(2)
	else:
		print(str(n[i2] % 2))


r = int(input())
for i in range(r):
	n = int(input())
	if n <= 2:
		ans = 4 - n
	elif n % 2 == 0:
		ans = 0
	elif n % 2 != 0:
		ans = 1
	print(ans)


a = int(input())
i = 0
for i in range(a):
	b = int(input())
	if b % 2 == 0 and b >= 4:
		print(0)
	if b % 2 == 1 and b >= 4:
		print(1)
	if b >= 0 and b < 4:
		if b == 0:
			print(4)
		if b == 1:
			print(3)
		if b == 2:
			print(2)
		if b == 3:
			print(1)


a = int(input())
b = list()
r = 0
while r < a:
	s = int(input())
	b.append(s)
	r = r + 1
r = 0
while r < a:
	if b[r] == 1:
		print(3)
	elif b[r] == 2:
		print(2)
	elif b[r] % 2 == 0:
		print(0)
	else:
		print(1)
	r = r + 1


import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

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

def function(n, q):
	for query in q:
		if query == 2:
			print(2)
		if query % 2 == 0 and query > 2:
			print(0)
		if query % 2 == 1:
			print(1)
n = inp()
q = []
for i in range(n):
	q.append(inp())
function(n, q)


n = int(input())
parms = [next(map(int, input().split())) for i in range(n)]
for i in parms:
	if i < 4:
		print(4 - i)
	else:
		print(i % 2)


n = int(input())
for i in range(n):
	angka = int(input())
	if angka > 2:
		if angka % 2 == 0:
			hasil = 0
		else:
			hasil = 1
	elif angka == 2:
		hasil = 2
	print(hasil)


c = int(input())
for x in range(c):
	a = int(input())
	b = int(a / 2)
	if a <= 4:
		a = 4 - a
	else:
		a = a - 2 * b
	print(a)


count = int(input())
output = []
for i in range(count):
	ch = int(input())
	if ch <= 4:
		output.append(4 - ch)
	elif ch % 2 == 0:
		output.append(0)
	else:
		output.append(1)
for i in range(len(output)):
	print(output[i])


n = int(input())
rezi = ''
for i in range(n):
	a = int(input())
	if a < 4:
		rez = 4 - a
	elif a % 2 == 1:
		rez = 1
	else:
		rez = 0
	rezi = rezi + str(rez)
for i in range(n):
	print(rezi[i])


n = int(input(''))
X = []
for i in range(n):
	temp = int(input(''))
	X.append(temp)
Y = []
for i in X:
	if i == 2:
		Y.append(2)
	elif i % 2 == 0:
		Y.append(0)
	else:
		Y.append(1)
for i in Y:
	print(i)


n = int(input())
lst = []
for i in range(n):
	lst.append(int(input()))
for i in lst:
	if i == 2:
		print(2)
	elif i % 2 == 0:
		yo = i // 2
		no = i - yo
		if yo == no:
			print(0)
		else:
			print(yo - no)
	else:
		yo = (i + 1) // 2
		no = i - yo
		if yo == no:
			print(0)
		else:
			print(yo - no)


iters = int(input())
A = B = []
for i in range(iters):
	A.append(int(input()))
for i in range(iters):
	if A[i] == 2:
		B[i] = 2
		continue
	if A[i] % 2 == 0:
		B[i] = 0
	else:
		B[i] = 1
for i in B:
	print(i)


q = int(input(''))
i = 1
while i <= q:
	item = int(input(''))
	if item == 2:
		print('2')
	elif item % 2 == 0:
		print('0')
	else:
		print('1')
	i += 1


n = int(input())
matches = [int(input()) for _ in range(n)]
for i in matches:
	if i == 2:
		print('2')
	elif i % 2 == 0:
		print('0')
	else:
		print('1')


testzahl = int(input())
querys = []
for i in range(testzahl):
	querys.append(int(input()))

def fun(n):
	if n == 1:
		print(3)
	elif n % 2 == 1:
		print(1)
	elif n == 2:
		print(2)
	else:
		print(0)
for i in querys:
	fun(i)


def cme(ar):
	for i in ar:
		if i < 4:
			print(4 - i)
		elif i % 2 == 1:
			print(1)
		else:
			print(0)
count = int(input())
ar = []
for _ in range(0, count):
	ar.append(int(input()))
cme(ar)


import math
q = int(input())
ans = int(0)
for i in range(q):
	a = int(input())
	if a <= 4:
		ans = 4 - a
	else:
		ans = math.ceil(a / 2) * 2 - a
	print(ans)