We have a point $A$ with coordinate $x = n$ on $OX$-axis. We'd like to find an integer point $B$ (also on $OX$-axis), such that the absolute difference between the distance from $O$ to $B$ and the distance from $A$ to $B$ is equal to $k$. [Image] The description of the first test case. 

Since sometimes it's impossible to find such point $B$, we can, in one step, increase or decrease the coordinate of $A$ by $1$. What is the minimum number of steps we should do to make such point $B$ exist?


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 6000$) — the number of test cases.

The only line of each test case contains two integers $n$ and $k$ ($0 \le n, k \le 10^6$) — the initial position of point $A$ and desirable absolute difference.


-----Output-----

For each test case, print the minimum number of steps to make point $B$ exist.


-----Example-----
Input
6
4 0
5 8
0 1000000
0 0
1 0
1000000 1000000

Output
0
3
1000000
0
1
0



-----Note-----

In the first test case (picture above), if we set the coordinate of $B$ as $2$ then the absolute difference will be equal to $|(2 - 0) - (4 - 2)| = 0$ and we don't have to move $A$. So the answer is $0$.

In the second test case, we can increase the coordinate of $A$ by $3$ and set the coordinate of $B$ as $0$ or $8$. The absolute difference will be equal to $|8 - 0| = 8$, so the answer is $3$. [Image]

Difficulty: EASY

Solutions:
from sys import stdin, stdout
input = stdin.buffer.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n < k:
		print(k - n)
	else:
		print(k + n & 1)


N = int(input())
for i in range(N):
	(n, k) = map(int, input().split())
	if n < k:
		print(k - n)
	elif abs(n - k) % 2 == 0:
		print(0)
	else:
		print(1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(k - n)
	elif (n + k) % 2 == 0:
		print('0')
	else:
		print('1')


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split(' '))
	if b > a:
		print(b - a)
	elif a % 2 == 0 and b % 2 == 0 or (a % 2 == 1 and b % 2 == 1):
		print(0)
	else:
		print(1)


test = int(input())
for t in range(test):
	(n, k) = map(int, input().split())
	if k > n:
		print(k - n)
	elif k == n:
		print(0)
	elif (n - k) % 2 == 0:
		print(0)
	else:
		print(1)


for g in [*open(0)][1:]:
	(n, k) = map(int, g.split())
	print([n - k & 1, k - n][n < k])


from sys import stdin, stdout

def soln(n, k):
	if k >= n:
		return abs(k - n)
	else:
		return n & 1 ^ k & 1
t = int(stdin.readline())
while t > 0:
	t -= 1
	(n, k) = [int(x) for x in stdin.readline().split()]
	print(soln(n, k))


t = int(input())
while t:
	line = input().split()
	(n, k) = (int(line[0]), int(line[1]))
	if k > n:
		print(k - n)
	else:
		print((n - k) % 2)
	t -= 1


import os
import sys
from io import BytesIO, IOBase

def main():
	pass
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')
main()
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(abs(n - k))
	elif (n + k) % 2 != 0:
		print(1)
	else:
		print(0)


t = int(input())
for i in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	if n > k:
		if n % 2 == 0 and k % 2 == 0:
			print('0')
		elif n % 2 == 0 and k % 2 == 1:
			print('1')
		elif n % 2 == 1 and k % 2 == 0:
			print('1')
		elif n % 2 == 1 and k % 2 == 1:
			print('0')
	elif n < k:
		print(k - n)
	else:
		print('0')


mod = 10 ** 9 + 7

def solve():
	(n, k) = map(int, input().split())
	ans = 0
	if k == 0:
		if n % 2 > 0:
			ans = 1
	else:
		ans = abs(n - k)
		if n > k:
			n -= k
			ans = n % 2
	print(ans)
t = 1
t = int(input())
while t > 0:
	solve()
	t -= 1


def main():
	T = int(input())
	for _ in range(T):
		(n, k) = map(int, input().split())
		if (n - k) % 2 == 0 and n - k >= 0:
			print(0)
		elif n - k < 0:
			print(k - n)
		else:
			print(1)
main()


for z in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(k - n)
	elif n % 2 == 0 and k % 2 == 0 or (n % 2 and k % 2):
		print('0')
	else:
		print('1')


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a >= b:
		print((a - b) % 2)
	else:
		print(b - a)


def compute_steps(n, k):
	if k > n:
		return int(k - n)
	mid_point = n / 2
	if k == 0 and int(mid_point) == mid_point:
		return 0
	steps = 0
	while 1:
		z = (k + n) / 2
		if int(z) == z:
			return int(steps)
		else:
			n += 1
			steps += 1
inputs_list = []
inputs_num = int(input())
while inputs_num > 0:
	input_data = input().split(' ')
	inputs_list.append(input_data)
	inputs_num -= 1
for i in inputs_list:
	print(compute_steps(float(i[0]), float(i[1])))


x = int(input())
for i in range(0, x):
	(n, m) = [int(a) for a in input().split()]
	if n > m:
		if n % 2 == m % 2:
			s = 0
		else:
			s = 1
	else:
		s = abs(m - n)
	print(s)


from math import ceil
from sys import stdin, stdout, setrecursionlimit
from random import randint
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	ans = 0
	if n < k:
		ans += k - n
		n = k
	if (n - k) % 2 == 1:
		ans += 1
	print(ans)


N = int(input())
i = 0
while i < N:
	(A, dis) = list(map(int, input().split()))
	if dis <= A:
		c = 0
		while (c + A - dis) % 2:
			c += 1
		print(c)
	else:
		print(dis - A)
	i += 1


for t in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a1 = abs(n - k)
	if n <= k:
		a2 = abs(n - k)
	elif (n + k) % 2 == 1:
		a2 = 1
	else:
		a2 = 0
	print(min(a1, a2))


for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if a > b:
		if a % 2 == 0 and b % 2 or (a % 2 and b % 2 == 0):
			print(1)
		else:
			print(0)
	else:
		print(b - a)


import sys
tc = int(sys.stdin.readline())
for _ in range(tc):
	(n, k) = map(int, sys.stdin.readline().split())
	if n < k:
		print(abs(k - n))
	elif (n - k) % 2 == 0:
		print(0)
	else:
		print(1)


import sys
import math

def scan(input_type='int'):
	return list(map(int, sys.stdin.readline().strip().split()))

def solution():
	for _ in range(int(input())):
		(n, k) = scan()
		if k > n:
			print(k - n)
		elif n % 2 == k % 2:
			print(0)
		else:
			print(1)
solution()


def fn(a, d):
	if a == d:
		return 0
	elif d > a:
		return d - a
	elif d % 2 == a % 2:
		return 0
	else:
		return 1
T = int(input())
for _ in range(T):
	(a, d) = map(int, input().split(' '))
	print(fn(a, d))


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().split())
inl = lambda : list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))
ans = []
t = ini()
for _ in range(t):
	(n, k) = inm()
	if n < k:
		ans.append(k - n)
	else:
		ans.append((n - k) % 2)
out(ans)


from sys import stdin, stdout
t = int(stdin.readline())
for case in range(t):
	(n, k) = map(int, stdin.readline().split())
	if k <= n:
		if k % 2 == n % 2:
			print(0)
		else:
			print(1)
	else:
		print(k - n)


for i in range(int(input())):
	(a, k) = map(int, input().split(' '))
	if k > a:
		print(k - a)
	elif a % 2 == k % 2:
		print('0')
	else:
		print('1')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n < k:
		print(k - n)
		continue
	for ans in range(2):
		a = n + ans
		if (a - k) % 2 == 0:
			print(ans)
			break


def diff(n, k):
	if k > n:
		result = k - n
	elif k == n:
		result = 0
	elif (n - k) % 2 == 0:
		result = 0
	else:
		result = 1
	return result
a = int(input())
for i in range(a):
	b = [int(x) for x in input().split()]
	res = diff(b[0], b[1])
	print(res)


import sys
import math

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

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

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

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

def solve():
	(n, k) = MI()
	if k > n:
		print(k - n)
	else:
		a = int(n % 2 != k % 2)
		print(a)
tests = 1
t = 1
if tests == 1:
	t = II()
for q in range(t):
	solve()


from collections import defaultdict
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n == k:
		print(0)
	elif k > n:
		print(abs(k - n))
	elif n % 2 == k % 2:
		print(0)
	else:
		print(1)


import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n >= k:
		if n % 2 == 0 and k & 1:
			print(1)
		elif n & 1 and k % 2 == 0:
			print(1)
		else:
			print(0)
	else:
		print(k - n)


t = int(input())
for _ in range(t):
	(a, k) = map(int, input().split())
	s = (a - k) / 2
	if s >= 0:
		if s.is_integer():
			print(0)
		else:
			a1 = 2 * int(s) + k
			a2 = 2 * (int(s) + 1) + k
			print(min(a - a1, a2 - a))
	else:
		print(abs(k - a))


from math import *
from collections import *
from itertools import *
from functools import *
from bisect import *
from heapq import *
from operator import *
from sys import *
setrecursionlimit(100000000)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = 0
	if n < k:
		ans = k - n
	if n > k:
		if n & 1:
			if k & 1 == 0:
				ans = 1
		elif k & 1:
			ans = 1
	print(ans)


import math as mt

def tran(arr):
	if arr[1] > arr[0]:
		return arr[1] - arr[0]
	elif arr[1] % 2 == 0:
		if arr[0] % 2 == 0:
			return 0
		else:
			return 1
	elif arr[0] % 2 == 1:
		return 0
	else:
		return 1
t = int(input())
ans = []
for i in range(t):
	arr = list(map(int, input().rstrip().split()))
	r = tran(arr)
	ans.append(r)
for i in ans:
	print(i)


def solve():
	(n, k) = map(int, input().split())
	if k > n:
		print(k - n)
	elif n % 2 == k % 2:
		print(0)
	else:
		print(1)
t = int(input())
for i in range(t):
	solve()


T = int(input())
for i in range(T):
	(A, k) = map(int, input().split())
	if k >= A:
		print(k - A)
	elif (A + k) % 2 == 0:
		print('0')
	else:
		print('1')


n = int(input())
answers = []
for a in range(n):
	line = input().split()
	ans = 0
	n = int(line[0])
	k = int(line[1])
	if n < k:
		answers.append(k - n)
	elif n % 2 == k % 2:
		answers.append(0)
	else:
		answers.append(1)
for b in answers:
	print(b)


import sys
input = sys.stdin.readline
T = int(input())
for t in range(T):
	(N, K) = [int(_) for _ in input().split()]
	if K > N:
		print(K - N)
	elif N % 2 and K % 2 or (not N % 2 and (not K % 2)):
		print(0)
	else:
		print(1)


import math
for i in range(int(input())):
	(a, d) = map(int, input().split())
	if d > a:
		print(d - a)
	else:
		print(a - d & 1)


def sol(a, k):
	if a == k:
		return 0
	elif k > a:
		return k - a
	elif (k - a) % 2 == 0:
		return 0
	else:
		return 1
n = int(input())
for _ in range(n):
	(a, k) = map(int, input().split())
	print(sol(a, k))


import math
t = int(input())
while t != 0:
	(n, k) = map(int, input().split())
	if n <= k:
		print(k - n)
	else:
		print((k - n) % 2)
	t -= 1


from sys import stdin

def inp():
	return stdin.buffer.readline().rstrip().decode('utf8')

def itg():
	return int(stdin.buffer.readline())

def mpint():
	return map(int, stdin.buffer.readline().split())
for case in range(1, itg() + 1):
	(a, k) = mpint()
	if a == k:
		print(0)
	elif 0 <= (a + k) / 2 <= a:
		if a + k & 1:
			print(1)
		else:
			print(0)
	else:
		print(abs(k - a))


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

def intPut():
	return int(input())

def arrIt(arr, n):
	result = 0
	for i in arr:
		result += i
	return result

def solve(n, k):
	result = 0
	if k > n:
		return abs(n - k)
	if k == 0:
		if n % 2 == 0:
			return 0
		else:
			return 1
	elif n % 2 == 0 and k % 2 == 0:
		return 0
	elif n % 2 != 0 and k % 2 != 0:
		return 0
	else:
		return 1
for _ in range(intPut()):
	(n, k) = readA()
	print(solve(n, k))


import math
t = int(input())
while t:
	(a, k) = [int(x) for x in input().split(' ')]
	if k <= a:
		print((a + k) % 2)
	else:
		print(k - a)
	t -= 1


t = int(input())
i = 0
while i < t:
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	if n < k:
		print(abs(n - k))
	elif n > k:
		v = 0
		while (n - k - v) % 2 != 0:
			v += 1
		print(v)
	else:
		print(0)
	i += 1


def axis(n, k):
	if n >= k:
		if (n + k) % 2 == 0:
			return 0
		return 1
	return k - n
res = []
n = int(input())
for i in range(n):
	arr = list(map(int, input().split()))
	res.append(axis(arr[0], arr[1]))
for j in res:
	print(j)


a = int(input())
while a > 0:
	l = list(map(int, input().split(' ')))
	k = (l[0] + l[1]) / 2
	k1 = (l[0] + l[1]) // 2
	i = 0
	if k <= l[0]:
		if k == k1:
			i = 0
		else:
			i = 1
	else:
		i = l[1] - l[0]
	print(i)
	a = a - 1


for _ in range(int(input())):
	s = input().split()
	(n, k) = (int(s[0]), int(s[1]))
	if k > n:
		print(k - n)
	else:
		print((n - k) % 2)


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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
from collections import Counter, defaultdict, deque

def int1():
	return int(input())

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

def list1():
	return list(map(int, input().split()))
mod = pow(10, 9) + 7

def solve():
	(n, k) = map1()
	if n == k:
		print(0)
	elif n < k:
		print(k - n)
	elif n % 2 == k % 2:
		print(0)
	else:
		print(1)
for _ in range(int(input())):
	solve()


from sys import stdin, stdout
import math
print = stdout.write
input = stdin.readline
for i in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(str(k - n) + '\n')
	elif n % 2 == 1 and k % 2 == 0:
		print('1' + '\n')
	elif n % 2 == 0 and k % 2 == 1:
		print('1' + '\n')
	else:
		print('0' + '\n')


n = int(input())
a = [int(j) for i in range(n) for j in input().split()]
for i in range(0, n * 2, 2):
	if a[i] <= a[i + 1]:
		print(abs(a[i] - a[i + 1]))
	elif a[i] % 2 == 0 and a[i + 1] % 2 == 0 or (a[i] % 2 != 0 and a[i + 1] % 2 != 0):
		print(0)
	elif a[i] % 2 != 0 and a[i + 1] % 2 == 0 or (a[i] % 2 == 0 and a[i + 1] % 2 != 0):
		print(1)


def answer(n, k):
	if k == 0:
		if n % 2 != 0:
			return 1
		return 0
	if k >= n:
		return k - n
	if k < n:
		if abs(n - k) % 2 == 0:
			return 0
		return 1
for _ in range(int(input())):
	(n, k) = input().split(' ')
	(n, k) = (int(n), int(k))
	print(answer(n, k))


def Solve(n, k):
	if n == k:
		return 0
	if n % 2 == 0:
		if k % 2 == 0:
			if n > k:
				return 0
			else:
				return k - n
		elif n > k:
			return Solve(n - 1, k) + 1
		else:
			return Solve(n + 1, k) + 1
	elif k % 2 == 0:
		if n > k:
			return Solve(n - 1, k) + 1
		else:
			return Solve(n + 1, k) + 1
	elif n > k:
		return 0
	else:
		return k - n
T = int(input())
for i in range(T):
	(n, k) = map(int, input().split())
	if k == 0:
		if n % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		print(Solve(n, k))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(max(k - n, int(n % 2 != k % 2)))


t = int(input())
while t != 0:
	(n, k) = map(int, input().split())
	if n == k:
		print(0)
	elif n < k:
		print(k - n)
	elif n > k:
		if n & 1 == 0 and k & 1 == 0:
			print(0)
		elif n & 1 == 1 and k & 1 == 1:
			print(0)
		else:
			print(1)
	t -= 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k <= n:
		print((n - k) % 2)
	else:
		print(k - n)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	if n == x:
		print(0)
	elif n > x:
		if n % 2 == 0 and x % 2 == 0:
			print(0)
		elif n % 2 != 0 and x % 2 != 0:
			print(0)
		else:
			print(1)
	else:
		print(x - n)


import os, sys, io, math
from array import array
from math import *
I = lambda : [*map(int, sys.stdin.readline().split())]
IS = lambda : input()
IN = lambda : int(input())
IF = lambda : float(input())
for _ in range(IN()):
	(n, k) = map(int, input().split())
	if n < k:
		print(k - n)
	elif n & 1 == k & 1:
		print(0)
	else:
		print(1)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if abs(n) >= k:
		if abs(n) % 2 == 0 and k % 2 == 0 or (abs(n) % 2 == 1 and k % 2 == 1):
			print('0')
		else:
			print('1')
	else:
		print(abs(n - k))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if b >= a:
		print(b - a)
	elif a % 2 == b % 2:
		print(0)
	else:
		print(1)


n = int(input())
for i in range(n):
	(A, k) = [int(x) for x in input().split()]
	det = (A + k) / 2
	out = 0
	if k > A:
		out = k - A
	elif det - int(det) != 0:
		out = 1
	print(out)


from sys import stdin, stdout
I = stdin.readline
print = stdout.write
for _ in range(int(I())):
	(n, k) = map(int, I().split())
	if n <= k:
		print(str(k - n))
		print('\n')
	elif n > k:
		if n - k & 1:
			print(str(1))
			print('\n')
		else:
			print(str(0))
			print('\n')


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from bisect import bisect_right as br
from bisect import bisect
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')

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))
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 zerolist(n):
	return [0] * n

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

def testcase(t):
	for p in range(t):
		solve()
from random import randint
from collections import defaultdict, deque

class Graph(object):

	def __init__(self, dic):
		self.dict = dic
		self.vertex = set()

	def addedge(self, a, b):
		if self.dict[a] == []:
			self.vertex.add(a)
		if b != None:
			self.dict[a].append(b)

	def con_com_util(self, i, unvisited, count, comp):
		for j in self.dict[i]:
			if j in unvisited:
				unvisited.remove(j)
				comp[count].append(j)
				comp = self.con_com_util(j, unvisited, count, comp)
		return comp

	def conn_components(self):
		unvisited = self.vertex.copy()
		count = 0
		comp = defaultdict(list)
		while unvisited:
			i = unvisited.pop()
			comp[count].append(i)
			comp = self.con_com_util(i, unvisited, count, comp)
			count += 1
		return (count, comp)

def countSetBits(n):
	count = 0
	while n:
		n &= n - 1
		count += 1
	return count
from bisect import bisect_left as bl

def solve():
	(a, k) = sep()
	if a <= k:
		print(k - a)
	elif (a + k) % 2 == 0:
		print(0)
	else:
		print(1)
testcase(int(inp()))


t = int(input())
outs = []
for i in range(t):
	(n, k) = map(int, input().split())
	out = 0
	if k > n:
		out = k - n
	elif (k + n) % 2 == 0:
		out = 0
	else:
		out = 1
	outs.append(out)
for out in outs:
	print(out)


def iin():
	return int(input())

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

def main():
	T = iin()
	while T:
		T -= 1
		(n, k) = lin()
		ans = n - k
		if ans < 0:
			ans = abs(ans)
		else:
			ans = ans % 2
		print(ans)
main()


t = int(input())
i = 0
while i < t:
	nk = list(map(int, input().split()))
	n = nk[0]
	k = nk[1]
	if k == 0:
		if n % 2 == 0:
			print(0)
			i += 1
			continue
		else:
			print(1)
			i += 1
			continue
	if k >= n:
		print(k - n)
		i += 1
		continue
	if k < n:
		if (k + n) % 2 == 0:
			print(0)
			i += 1
			continue
		else:
			print(1)
			i += 1
			continue


def fun(ls):
	n = ls[0]
	k = ls[1]
	if n % 2 != 0 and k % 2 == 0 and (k < n):
		print(1)
		return
	if n % 2 == 0 and k % 2 != 0 and (k < n):
		print(1)
		return
	if k <= n:
		print(0)
	if k > n:
		print(k - n)
T = int(input())
for i in range(T):
	x = input().split()
	x = list(map(int, x))
	fun(x)


import sys

def FastInt(zero=0):
	(_ord, nums, num, neg) = (lambda x: x, [], zero, False)
	(i, s) = (0, sys.stdin.buffer.read())
	try:
		while True:
			if s[i] >= b'0'[0]:
				num = 10 * num + _ord(s[i]) - 48
			elif s[i] == b'-'[0]:
				neg = True
			elif s[i] != b'\r'[0]:
				nums.append(-num if neg else num)
				(num, neg) = (zero, False)
			i += 1
	except IndexError:
		pass
	if s and s[-1] >= b'0'[0]:
		nums.append(-num if neg else num)
	return nums
inp = FastInt()
_Index = 0

def fin(size=None):
	global _Index
	if size == None:
		ni = _Index
		_Index += 1
		return inp[ni]
	else:
		ni = _Index
		_Index += size
		return inp[ni:ni + size]
_T_ = fin()
for _t_ in range(_T_):
	(n, k) = fin(2)
	if k > n:
		print(k - n)
	elif k % 2:
		if n % 2:
			print(0)
		else:
			print(1)
	elif n % 2:
		print(1)
	else:
		print(0)


import sys
I = lambda : int(input())
readline = lambda : sys.stdin.readline().strip('\n')
RM = readgen = lambda : map(int, readline().split(' '))
for _ in range(I()):
	(n, k) = RM()
	if n <= k:
		print(k - n)
	else:
		print((n - k) % 2)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	moves = 0
	if k > n:
		moves += k - n
	elif k < n:
		if (n - k) / 2 - (n - k) // 2 > 0:
			moves += 1
	print(moves)


import sys
import collections

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

def split_input():
	return [int(i) for i in input().split()]
tests = int(input())
for _ in range(tests):
	(n, k) = split_input()
	if k >= n:
		print(k - n)
	else:
		print(int(k % 2 != n % 2))


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 *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
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')

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 zerolist(n):
	return [0] * n

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

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

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

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

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	(n, k) = sep()
	ans = 0
	if k % 2 == 0:
		if n % 2 == 1:
			ans += 1
			n += 1
		if k > n:
			ans += k - n
		print(ans)
	else:
		if n % 2 == 0:
			ans += 1
			n += 1
		if k > n:
			ans += k - n
		print(ans)
testcase(int(inp()))


import sys
input = lambda : sys.stdin.readline().rstrip()
n = int(input())
for i in range(n):
	(x, y) = map(int, input().split())
	if y >= x:
		print(y - x)
	elif x - y & 1:
		print(1)
	else:
		print(0)


n = int(input())
_list = []
for x in range(n):
	(a, b) = map(int, input().split())
	tuple1 = (a, b)
	_list.append(tuple1)
for Tuple in _list:
	if Tuple[0] >= Tuple[1]:
		if (Tuple[0] - Tuple[1]) % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		print(Tuple[1] - Tuple[0])


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(abs(k - n))
	else:
		i = 0
		while (n - k) / 2 != (n - k) // 2:
			n = n + 1
			i += 1
		print(i)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		(a, b) = list(map(int, input().split()))
		if b > a:
			yield (b - a)
		elif a % 2 == b % 2:
			yield 0
		else:
			yield 1
t = int(input())
ans = gift()
print(*ans, sep='\n')


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

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

def si():
	return input().rstrip()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')
file = 1

def solve():
	for _ in range(ii()):
		(x, y) = mi()
		if x <= y:
			print(y - x)
		elif y - x & 1:
			print(1)
		else:
			print(0)
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


import math
t = int(input())
for _ in range(t):
	(m, n) = map(int, input().split())
	if m <= n:
		print(n - m)
	else:
		a = math.ceil((m - n) / 2)
		a = a * 2 + n
		print(a - m)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n > k:
		ns = n % 2
		ks = k % 2
		if ns == ks:
			print(0)
		else:
			print(1)
	else:
		print(k - n)


for _ in range(int(input())):
	X = list(map(int, input().split()))
	if X[1] >= X[0]:
		print(X[1] - X[0])
		continue
	print(0 if len(set([X[1] % 2, X[0] % 2])) == 1 else 1)


for t in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if n == k:
		print(0)
	elif k > n:
		print(k - n)
	else:
		i = 0
		while True:
			x = (k + i - n) / 2
			if float(x).is_integer():
				break
			else:
				i += 1
		print(i)


for T in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(k - n)
		continue
	diff = n - k
	if diff % 2 == 0:
		print(0)
	else:
		print(1)


TestCases = int(input())
for i in range(TestCases):
	Inputs = list(map(int, input().split()))
	Origin = Inputs[0]
	K = Inputs[1]
	if K == Origin:
		print(0)
	elif Origin > K:
		if Origin % 2 == K % 2:
			print(0)
		else:
			print(1)
	else:
		print(K - Origin)


for _ in range(int(input().strip())):
	(n, k) = map(int, input().strip().split(' '))
	if n >= k:
		(x, y) = ((n - k) // 2, (n + k) // 2)
		(dx, dy) = (n - x, n - y)
		print(min(abs(k - abs(x - dx)), abs(k - abs(y - dy))))
	else:
		print(k - n)


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

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

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
for _ in range(int(input())):
	(n, k) = mapi()
	if k > n:
		print(k - n)
	else:
		print((k - n) % 2)


def short(n, k):
	if k > n:
		return k - n
	elif (n + k) % 2 == 1:
		return 1
	return 0
t = int(input(''))
l = []
for i in range(t):
	nk = input('')
	(n, k) = map(int, nk.split())
	c = short(n, k)
	l.append(c)
for c in l:
	print(c)


query = int(input())
for _ in range(query):
	(a, k) = map(int, input().split())
	if k == 0:
		if a % 2 == 0:
			print(0)
		else:
			print(1)
	elif k > a:
		print(k - a)
	elif (a - k) % 2 == 0:
		print(0)
	else:
		print(1)


for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	if n == 0 and k == 0:
		print(0)
	elif n == k:
		print(0)
	elif n < k:
		print(k - n)
	else:
		print((n + k) % 2)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n == k:
		print(0)
		continue
	if k == 0:
		if n & 1 == 0:
			print(0)
		else:
			print(1)
		continue
	if n == 0:
		print(k)
		continue
	elif k < n:
		if n & 1 == 0:
			if k & 1 == 0:
				print(0)
			else:
				print(1)
		elif k & 1 == 1:
			print(0)
		else:
			print(1)
	else:
		print(abs(n - k))


from sys import stdin
from collections import Counter, defaultdict
from math import gcd
input = stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if n % 2 == 0:
		if m <= n:
			if m % 2 == 1:
				print(1)
			else:
				print(0)
		else:
			print(m - n)
	elif m <= n:
		if m % 2 == 0:
			print(1)
		else:
			print(0)
	else:
		print(m - n)


t = int(input())
ans = []
while t:
	(n, k) = map(int, input().split())
	if n < k:
		ans.append(k - n)
	elif n % 2 != k % 2:
		ans.append(1)
	else:
		ans.append(0)
	t = t - 1
for i in ans:
	print(i)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if k > n:
		ans = k - n
	elif n % 2 == k % 2:
		ans = 0
	else:
		ans = 1
	print(ans, flush=False)


tt = int(input())
while tt:
	tt -= 1
	m = list(map(int, input().split()))
	n = m[0]
	k = m[1]
	if n == k:
		print('0')
	elif k > n:
		print(k - n)
	elif k % 2 == 0 and n % 2 == 0 or (k % 2 != 0 and n % 2 != 0):
		print('0')
	else:
		print('1')


import math
t = int(input())
for i in range(t):
	arr = list(map(int, input().split()))
	a = arr[0]
	k = arr[1]
	if a == k:
		print('0')
		continue
	if a == 0:
		print(k)
		continue
	if a < k:
		print(k - a)
		continue
	if a > k:
		c = 0
		while True:
			b = (a + k) / 2
			b_1 = abs(math.floor(b))
			if b - b_1 < 1e-09:
				print(c)
				break
			a += 1
			c += 1


s = int(input())
for i in range(s):
	m = list(map(int, input().split()))
	n = m[0]
	k = m[1]
	if k == 0 and n % 2 == 0:
		print('0')
	elif k == 0 and n % 2 != 0:
		print('1')
	elif n == k:
		print('0')
	elif n < k:
		print(k - n)
	elif n > k:
		if (n + k) % 2 == 0:
			print('0')
		else:
			print('1')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n < k:
		print(k - n)
	else:
		a = (n + k) / 2
		if a == int(a):
			print(0)
		else:
			c = 0
			while (n + k) / 2 != int((n + k) / 2):
				c += 1
				n += 1
			print(c)


def main():
	for _ in range(int(input())):
		(a, k) = map(int, input().split())
		if k > a:
			print(k - a)
			continue
		elif k == a:
			print(0)
			continue
		elif k == 0:
			if a % 2 != 0:
				print(1)
			else:
				print(0)
		elif k % 2 == 0 and a % 2 == 0 or (k % 2 != 0 and a % 2 != 0):
			print(0)
		else:
			print(1)
main()


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n >= k:
		ans = (n - k) % 2
		print(ans)
	else:
		ans = k - n
		print(ans)


num = int(input())
inp = []
for i in range(0, num):
	inp.append(list(map(int, input().strip().split())))
for i in range(0, num):
	n = inp[i][0]
	k = inp[i][1]
	if n > k:
		if (n - k) % 2 == 0:
			print('0')
		else:
			print('1')
	else:
		print(str(k - n))


for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	if n % 2:
		if k % 2:
			ans = max(k - n, 0)
		else:
			ans = 1 + max(k - n - 1, 0)
	elif k % 2:
		ans = 1 + max(k - n - 1, 0)
	else:
		ans = max(k - n, 0)
	print(ans)


import sys
input = sys.stdin.readline

def inInt():
	return int(input())

def inStr():
	return input().strip('\n')

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

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

def solve(n, k):
	if n < k:
		return k - n
	elif (n - k) % 2 == 0:
		return 0
	else:
		return 1
tests = inInt()
for t in range(tests):
	nk = inIList()
	print(solve(nk[0], nk[1]))


s = int(input())
while s:
	s = s - 1
	(a, d) = map(int, input().split())
	if a <= d:
		print(abs(a - d))
		continue
	if a % 2 == 0 and d % 2 == 0 or (a % 2 != 0 and d % 2 != 0):
		print(0)
	else:
		print(1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k > n:
		print(k - n)
	elif k <= n:
		a = (n - k) % 2
		print(a)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	from math import ceil
	if n < k:
		print(k - n)
	elif n > k:
		if (k + n) / 2 == (k + n) // 2:
			print(0)
		else:
			print(1)
	else:
		print(0)


T = int(input())
for t in range(T):
	tmp = input().split(' ')
	(n, k) = (int(tmp[0]), int(tmp[1]))
	if n > k:
		if (n + k) % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		print(k - n)


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	if n == 0:
		print(k)
	elif k == 0:
		print(n % 2)
	elif n == k:
		print(0)
	elif n < k:
		print(k - n)
	else:
		print((n - k) % 2)


t = int(input())
for i in range(t):
	l = list(map(int, input().split()))
	x = l[0]
	k = l[1]
	if x % 2 == 0:
		if k <= x:
			if k % 2 == 0:
				print(0)
			else:
				print(1)
		else:
			print(k - x)
	elif k <= x:
		if k % 2 != 0:
			print(0)
		else:
			print(1)
	else:
		print(k - x)


for _ in range(int(input())):
	(N, K) = map(int, input().split())
	if K > N:
		print(K - N)
	elif K % 2 == N % 2:
		print(0)
	else:
		print(1)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		print(k - n)
	elif n > k:
		print((n + k) % 2)


num_times = int(input())
for i in range(num_times):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	if n % 2 == 0:
		if k > n:
			print(k - n)
		elif k <= n and k % 2 == 0:
			print(0)
		elif k <= n and k % 2 != 0:
			print(1)
	elif n % 2 != 0:
		if k > n:
			print(k - n)
		if k % 2 != 0 and k <= n:
			print(0)
		elif k % 2 == 0 and k <= n:
			print(1)


n = int(input())
for i in range(n):
	kol = 0
	(n, k) = map(int, input().split())
	if n <= k:
		print(k - n)
		continue
	elif n % 2 == 1 and k % 2 == 0 or (n % 2 == 0 and k % 2 == 1):
		print(1)
		continue
	else:
		print(0)


t = int(input())
for i in range(t):
	(A, d) = input().split()
	A = int(A)
	d = int(d)
	if A == 0:
		print(d)
	elif A == d:
		print('0')
	elif A > d:
		if A % 2 == d % 2:
			print('0')
		else:
			print('1')
	elif A < d:
		print(d - A)


def exists(n, k):
	res = (n - k) / 2
	if res % 1 == 0:
		return True
	else:
		return False
t = int(input())
while t:
	(n, k) = map(int, input().split())
	count = 0
	if k > n:
		print(k - n)
	else:
		while True:
			if exists(n, k):
				print(count)
				break
			else:
				n += 1
				count += 1
	t -= 1


def calc(a, k):
	if k <= a:
		if k % 2 == 0:
			if a % 2 == 0:
				return 0
			else:
				return 1
		elif a % 2 == 0:
			return 1
		else:
			return 0
	else:
		return k - a
t = input()
for test in range(int(t)):
	ak = input()
	ak = ak.split()
	ak_list = [int(i) for i in ak]
	a = ak_list[0]
	k = ak_list[1]
	print(calc(a, k))


for _ in range(int(input())):
	(N, K) = map(int, input().split())
	print(max(K - N, 0, (K + N) % 2))


t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	if n == k:
		print(0)
	else:
		ans1 = abs(n - k)
		if n > k:
			if (n - k) % 2 == 0:
				print(0)
			else:
				print(1)
		else:
			print(ans1)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	print([(n + k) % 2, k - n][n < k])


t = int(input())
for j in range(t):
	(a, k) = [int(i) for i in input().split()]
	if k < a:
		print((k + a) % 2)
	elif k == a:
		print('0')
	else:
		print(abs(k - a))


t = int(input())
for _ in range(t):
	count = 0
	(a, b) = map(int, input().split())
	if b == 0:
		if a % 2 == 0:
			print('0')
		else:
			print('1')
	elif a <= b:
		print(b - a)
	else:
		while 1:
			if (a + b) % 2 == 0:
				print(count)
				break
			else:
				count += 1
				a = a + 1


for i in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	if n < k:
		print(k - n)
	else:
		print(0) if n % 2 == k % 2 else print(1)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	if k > n:
		print(abs(n - k))
	else:
		print((n - k) % 2)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	kq = 0
	if k > n:
		kq = k - n
		n = k
	if n > k and n % 2 != k % 2:
		kq = 1
	print(kq)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	c = k - n
	if c < 0:
		c = 0
		if n % 2 != k % 2:
			c = 1
	print(c)


def solve():
	if N <= K:
		return K - N
	if (N - K) % 2 == 1:
		return 1
	return 0
T = int(input())
for t in range(1, T + 1):
	(N, K) = [int(s) for s in input().split()]
	print(solve())


def ans():
	(a, k) = map(int, input().split())
	if a == k:
		return 0
	if not (a - k) % 2 and (a - k) / 2 >= 0:
		return 0
	if a > k:
		return 1
	return k - a
t = int(input())
for _ in range(t):
	print(ans())


T = int(input())
for z in range(T):
	(a, k) = input().split()
	(a, k) = (int(a), int(k))
	if k % 2 == 0:
		if a >= k:
			if a % 2 == 0:
				print(0)
			else:
				print(1)
		else:
			temp = a
			a = k
			if a % 2 == 0:
				print(k - temp)
			else:
				print(k - temp + 1)
	elif a >= k:
		if a % 2 == 0:
			print(1)
		else:
			print(0)
	else:
		temp = a
		a = k
		if a % 2 == 0:
			print(k - temp + 1)
		else:
			print(k - temp)


read = input
rn = lambda : list(map(int, read().split()))
T = rn()[0]
for i in range(T):
	(n, k) = rn()
	if k >= n:
		print(k - n)
	elif abs(n - k) % 2 == 1:
		print(1)
	else:
		print(0)


from __future__ import division, print_function
from sys import stdin, stdout
import bisect
import math
import heapq
i_m = 9223372036854775807

def inin():
	return int(input())

def stin():
	return input()

def spin():
	return map(int, stin().split())

def lin():
	return list(map(int, stin().split()))

def matrix(n):
	return [list(map(int, input().split())) for i in range(n)]

def count2Dmatrix(i, list):
	return sum((c.count(i) for c in list))

def modinv(n, p):
	return pow(n, p - 2, p)

def GCD(x, y):
	x = abs(x)
	y = abs(y)
	if min(x, y) == 0:
		return max(x, y)
	while y:
		(x, y) = (y, x % y)
	return x

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l
prime = []

def SieveOfEratosthenes(n):
	global prime
	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
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j
for _ in range(inin()):
	(n, k) = spin()
	if n < k:
		print(k - n)
	else:
		print((n + k) % 2)


t_case = int(input())
for i in range(t_case):
	n_k = str(input())
	(n, k) = (int(n_k.split(' ')[0]), int(n_k.split(' ')[1]))
	origi_n = n
	if n >= k:
		while (n - k) % 2 != 0:
			n = n + 1
		print(abs(origi_n - n))
	else:
		print(k - n)


def checkKey(dict, key):
	if key in dict:
		return True
	return False

def h(arr, dummy_arr, free, n):
	for i in range(n):
		if free[i] == False:
			if arr[i] == dummy_arr[i]:
				continue
			else:
				return False
	return True

def helper(arr, n):
	for i in range(1, n):
		if arr[i] >= arr[i - 1]:
			continue
		else:
			return False
	return True
test = int(input())
for t_ in range(test):
	(n, k) = map(int, input().split())
	if k >= n:
		print(k - n)
	elif n & 1 == k & 1:
		print(0)
	else:
		print(1)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	dif = b - a
	res = 0
	if dif >= 0:
		res = dif
	elif abs(dif) % 2 == 0:
		res = 0
	else:
		res = 1
	print(res)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a >= b:
		c = int((a + b) / 2)
		c1 = (a + b) / 2
		if c1 == c:
			print(0)
		else:
			cnt = 0
			while c1 != c:
				cnt += 1
				a += 1
				c = int((a + b) / 2)
				c1 = (a + b) / 2
			print(cnt)
	else:
		print(abs(a - b))


def ans(n, k):
	if n % 2 == 0:
		if k <= n:
			if k % 2 == 0:
				return 0
			else:
				return 1
		else:
			return k - n
	elif k <= n:
		if k % 2 == 0:
			return 1
		else:
			return 0
	else:
		return k - n
t = int(input())
L = []
for i in range(t):
	(n, k) = map(int, input().split())
	L.append(ans(n, k))
for l in L:
	print(l)


t = int(input())
while t:
	(n, k) = [int(e) for e in input().split()]
	if n <= k:
		print(k - n)
	elif abs(n - k) & 1:
		print(1)
	else:
		print(0)
	t -= 1


import sys
import math, bisect
from collections import defaultdict
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, OrderedDict

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

def Neo():
	return list(map(int, input().split()))
for _ in range(int(input())):
	(n, k) = neo()
	if k <= n:
		if n % 2 == 0 and k % 2 == 0:
			print(0)
		elif n % 2 == 0 and k % 2 != 0:
			print(1)
		elif n % 2 != 0 and k % 2 != 0:
			print(0)
		else:
			print(1)
	else:
		print(k - n)


t = int(input())
for i in range(t):
	(n, k) = [int(item) for item in input().split(' ')]
	print(k - n if n < k else (n - k) % 2)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if m > n:
		print(m - n)
	if m == n:
		print(0)
	if n > m:
		if m % 2 != 0 and n % 2 != 0:
			print(0)
		elif m % 2 == 0 and n % 2 == 0:
			print(0)
		elif m % 2 == 0 and n % 2 != 0:
			print(1)
		elif m % 2 != 0 and n % 2 == 0:
			print(1)


import sys
input = sys.stdin.readline
import heapq
import copy
import math
import decimal

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def insr2():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
ans = 0

def pr_list(a):
	print(*a, sep=' ')

def main():
	tests = inp()
	mod = 1000000007
	limit = 10 ** 18
	ans = 0
	stack = []
	hashm = {}
	arr = []
	heapq.heapify(arr)
	for test in range(tests):
		[n, k] = inlt()
		ans = 0
		if k > n:
			ans = ans + k - n
			n = k
		if (n - k) % 2 != 0:
			ans = ans + 1
		print(ans)
main()


for _ in range(int(input())):
	(A, diff) = map(int, input().split())
	if diff >= A:
		print(abs(diff - A))
	elif A & 1 ^ diff & 1:
		print(1)
	else:
		print(0)


import sys
input = lambda : sys.stdin.readline().strip()
char = [chr(i) for i in range(97, 123)]
CHAR = [chr(i) for i in range(65, 91)]
mp = lambda : list(map(int, input().split()))
INT = lambda : int(input())
rn = lambda : range(INT())
from math import ceil, sqrt, factorial, gcd
for _ in rn():
	(n, k) = mp()
	if k >= n:
		print(k - n)
	elif n % 2 == k % 2:
		print(0)
	else:
		print(1)


t = int(input())
a = []
k = []
for i in range(t):
	(x, y) = input().split()
	a.append(int(x))
	k.append(int(y))
for i in range(t):
	if a[i] <= k[i]:
		print(k[i] - a[i])
	elif (a[i] - k[i]) % 2 == 0:
		print(0)
	else:
		print(1)


t = int(input())
while t > 0:
	t -= 1
	(n, k) = map(int, input().split())
	if n == k:
		ans = 0
	elif k > n:
		ans = k - n
	elif n > k:
		if n % 2 == 0 and k % 2 == 0 or (n % 2 != 0 and k % 2 != 0):
			ans = 0
		else:
			ans = 1
	print(ans)


test = int(input())
while test:
	(n, k) = list(map(int, input().split()))
	if k == n:
		print(0)
	elif n < k:
		print(k - n)
	elif n % 2 == 0 and k % 2 == 0:
		print(0)
	elif n % 2 == 0 and k % 2 == 1:
		print(1)
	elif n % 2 == 1 and k % 2 == 1:
		print(0)
	else:
		print(1)
	test -= 1


import sys
sys.setrecursionlimit(10 ** 6)
from collections import Counter, defaultdict as dft

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

def ml():
	return list(map(int, input().split()))
mxn = 10 ** 9

def solve():
	(n, k) = mp()
	if n < k:
		t1 = k - n
	elif n % 2 == k % 2:
		t1 = 0
	else:
		t1 = 1
	print(t1)
t = int(input())
for _ in range(t):
	solve()


q = int(input())
for _ in range(q):
	(n, k) = map(int, input().split())
	dupa = 0
	if n < k:
		dupa = k - n
	n = max(n, k)
	if (n - k) % 2 == 0:
		print(0 + dupa)
	else:
		print(1 + dupa)


def count(a, k):
	if a < k:
		cost = k - a
		return cost
	cost = 0
	i = 2
	while 1:
		if (k + a) % 2 == 0:
			return cost
		cost += 1
		a += 1
t = int(input())
for i in range(0, t):
	(a, k) = map(int, input().split())
	k11 = count(a, k)
	print(k11)


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.buffer.readline().rstrip()
for _ in range(int(input())):
	(q, w) = map(int, input().split())
	if w > q:
		print(w - q)
	elif q % 2 != w % 2:
		print(1)
	else:
		print(0)


def f(a, b):
	if b > a:
		return b - a
	return (a - b) % 2
numberofcases = int(input())
for _ in range(numberofcases):
	(a, b) = [int(t) for t in input().split()]
	print(f(a, b))


t = int(input())
for x in range(t):
	(n, k) = list(map(int, input().split()))
	if k <= n:
		if (n - k) % 2 == 0:
			ans = 0
		else:
			ans = 1
	else:
		ans = k - n
	print(ans)


import math
t = int(input())
for p in range(t):
	(n, k) = map(int, input().split())
	if k > n:
		print(k - n)
	elif k % 2 == n % 2:
		print(0)
	else:
		print(1)


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(n, k) = input().split()
	x_pos = int(n)
	abs_distance = int(k)
	if x_pos < abs_distance:
		steps = abs_distance - x_pos
	elif (x_pos - abs_distance) % 2 == 0:
		steps = 0
	else:
		steps = 1
	print(steps)


import io, os

def FastInt(zero=0):
	(_ord, nums, num, neg) = (lambda x: x, [], zero, False)
	(i, s) = (0, io.BytesIO(os.read(0, os.fstat(0).st_size)).read())
	try:
		while True:
			if s[i] >= b'0'[0]:
				num = 10 * num + _ord(s[i]) - 48
			elif s[i] == b'-'[0]:
				neg = True
			elif s[i] != b'\r'[0]:
				nums.append(-num if neg else num)
				(num, neg) = (zero, False)
			i += 1
	except IndexError:
		pass
	if s and s[-1] >= b'0'[0]:
		nums.append(-num if neg else num)
	return nums
inp = FastInt()
ii = 0
_T_ = inp[ii]
ii += 1
for _t_ in range(_T_):
	(n, k) = inp[ii:ii + 2]
	ii += 2
	if k > n:
		print(k - n)
	elif k % 2:
		if n % 2:
			print(0)
		else:
			print(1)
	elif n % 2:
		print(1)
	else:
		print(0)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	if n < k:
		print(k - n)
	else:
		cond = False
		if n % 2 == 0:
			cond = True
		if k % 2 == 0:
			if cond:
				print(0)
			else:
				print(1)
		elif cond:
			print(1)
		else:
			print(0)


def ans():
	N = int(input())
	for i in range(N):
		A = input().strip().split()
		b = int(A[0])
		c = int(A[1])
		if b >= c and (c + b) % 2 == 0:
			print(0)
		elif b >= c:
			print(1)
		elif c > b:
			print(c - b)
ans()


import os
import heapq
import sys, threading
import math
import bisect
import operator
from collections import defaultdict
from io import BytesIO, IOBase

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

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

def inar():
	return [int(k) for k in input().split()]

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = inar()
		if k == 0:
			if n % 2 == 0:
				print(0)
			else:
				print(1)
		elif n >= k:
			if n % 2 == k % 2:
				print(0)
			else:
				print(1)
		else:
			print(k - 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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys, math, heapq, collections, itertools, bisect
sys.setrecursionlimit(101000)

def solve(n, k):
	nn = max(n, k)
	if nn % 2 != k % 2:
		nn += 1
	return nn - n
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print(solve(n, k))


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	if n < m:
		print(m - n)
		continue
	if n % 2 != m % 2:
		print(1)
		continue
	print(0)


import math, sys
from collections import defaultdict, Counter, deque
INF = float('inf')
MOD = 10 ** 9 + 7

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

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

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

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

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

def a():
	(n, k) = vars()
	if k >= n:
		print(k - n)
	elif n % 2 == k % 2:
		print(0)
	else:
		print(1)

def b():
	(z1, o1, t1) = vars()
	(z2, o2, t2) = vars()
	s1 = '0' * z1 + '1' * o1 + '2' * t1
	s2 = '2' * t2 + '0' * z2 + '1' * o2
	ans = 0
	for i in range(len(s1)):
		mul = int(s1[i]) * int(s2[i])
		if s1[i] > s2[i]:
			ans += mul
		if s1[i] < s2[i]:
			ans -= mul
	print(ans)

def c():
	n = int(input())
	arr = array()
	inc = sorted(arr)
	mini = min(arr)
	res = 'YES'
	for i in range(n):
		if arr[i] % mini != 0 and arr[i] != inc[i]:
			res = 'NO'
			break
	print(res)
t = 1
t = int(input())
for _ in range(t):
	a()


t = int(input())
for _ in range(t):
	a = list(map(int, input().split()))
	n = a[0]
	k = a[1]
	d = abs(k - n)
	if k >= n:
		print(abs(k - n))
	elif (k - n) % 2 == 0:
		print(0)
	else:
		print(1)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	var = abs(n - m)
	if m > n:
		print(var)
	else:
		print(var % 2)


import sys
input = iter(sys.stdin.read().splitlines()).__next__

def solve(n, k):
	if k >= n:
		return k - n
	x = n - k
	if x & 1 != 0:
		return 1
	return 0
TC = int(input())
for tc in range(TC):
	(n, k) = map(int, input().split())
	res = solve(n, k)
	print(res)


t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	if a - b <= 0:
		print(b - a)
	else:
		print(a - b & 1)


T = int(input())
i = 0
while i < T:
	(x, y) = input().split()
	x = int(x)
	y = int(y)
	if y >= x:
		print(y - x)
	elif x % 2 != 0 and y % 2 != 0:
		print(0)
	elif x % 2 != 0 and y % 2 == 0:
		print(1)
	elif x % 2 == 0 and y % 2 == 0:
		print(0)
	else:
		print(1)
	i = i + 1


t = int(input())
for case in range(t):
	(n, k) = [int(s) for s in input().split(' ')]
	if k > n:
		ans = k - n
	elif k % 2 != n % 2:
		ans = 1
	else:
		ans = 0
	print(ans)


for _ in range(int(input())):
	(A, K) = map(int, input().split())
	ans = 0
	if A < K:
		ans = K - A
	elif A == K:
		ans = 0
	elif (A - K) % 2 == 0:
		ans = 0
	else:
		ans = 1
	print(ans)


for _ in range(int(input())):
	(n, k) = [int(j) for j in input().split()]
	if k < n:
		if k % 2 == 0 and n % 2 == 0 or (k % 2 != 0 and n % 2 != 0):
			print(0)
		elif k % 2 != 0 and n % 2 == 0 or (k % 2 == 0 and n % 2 != 0):
			print(1)
	else:
		print(k - n)


def min_steps_find_b(n, k):
	if n >= k:
		if (n - k) % 2 == 0:
			return 0
		return 1
	return k - n
num_tests = int(input())
for _ in range(num_tests):
	(n, k) = input().split()
	print(min_steps_find_b(int(n), int(k)))


import sys
input = sys.stdin.readline
from collections import Counter

def read():
	(n, k) = map(int, input().strip().split())
	return (n, k)

def solve(n, k):
	ans = 0
	if n <= k:
		ans = k - n
	elif (n - k) % 2 == 0:
		ans = 0
	else:
		ans = 1
	return ans
T = int(input().strip())
for t in range(T):
	inputs = read()
	print('%s' % solve(*inputs))


t = int(input())
for j in range(t):
	(n, k) = map(int, input().split())
	if n >= k:
		if (n + k) % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		print(k - n)


from collections import Counter, defaultdict
from sys import stdin, stdout
input = stdin.readline
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
for _ in range(I()):
	(n, k) = M()
	if n >= k:
		if n % 2 == 0:
			if k % 2 == 0:
				print(0)
			else:
				print(1)
		elif k % 2 == 0:
			print(1)
		else:
			print(0)
	else:
		print(k - n)


import bisect
import math
for xoxo in range(1):
	for _ in range(int(input())):
		ans = 0
		(n, k) = map(int, input().split())
		if n <= k:
			print(abs(n - k))
		elif n % 2 == 0 and k % 2 == 0 or (n % 2 == 1 and k % 2 == 1):
			print('0')
		else:
			print('1')


t = input()
t = int(t)
while t > 0:
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	min_steps = None
	c = n - k
	if k > n:
		min_steps = k - n
	elif k == n:
		min_steps = 0
	elif k < n:
		if c % 2 == 0:
			min_steps = 0
		else:
			min_steps = 1
	t = t - 1
	print(min_steps)


for i in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if k > n:
		steps = k - n
	else:
		if (n - k) % 2 == 0:
			steps = 0
		else:
			steps = 1
		if (n + k) % 2 == 0:
			steps = 0
		else:
			steps = min(steps, 1)
	print(steps)


import math
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if m - n > 0:
		print(m - n)
	else:
		print((m - n) % 2)


t = int(input())
for _ in range(t):
	(a, k) = [int(p) for p in input().split()]
	if a - k < 0:
		print(abs(a - k))
	elif (a - k) % 2 != 0:
		print(1)
	else:
		print(0)


import sys
input = sys.stdin.readline
from bisect import bisect_left
from bisect import bisect_right
from math import ceil, factorial

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

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

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

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

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

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

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	(a, k) = int_array()
	b1 = (a - k) / 2
	b2 = (a + k) / 2
	if b1 >= 0 and b1 == int(b1):
		print(0)
	elif b1 >= -0.5:
		print(1)
	else:
		x = (0 - b1) / 0.5
		print(int(x))


for _ in range(int(input())):
	(i, j) = map(int, input().split())
	if j > i:
		print(j - i)
	else:
		print((i - j) % 2)


def main():
	for i in range(Iint()):
		(n, k) = Ilist()
		if k >= n:
			print(k - n)
		elif n % 2 == 0 and k % 2 == 0 or (n % 2 == 1 and k % 2 == 1):
			print(0)
		else:
			print(1)

def I():
	return input()

def Iint():
	return int(input())

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

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

def Plist(li, s=' '):
	print(s.join(map(str, li)))
main()


t = int(input(''))
for i in range(0, t):
	(n, r) = input('').split(' ')
	n = int(n)
	r = int(r)
	if n < r:
		print(r - n)
	elif n % 2 == r % 2:
		print(0)
	else:
		print(1)


import sys
import os

def solve(a, b):
	if a == b:
		return 0
	elif b == 0:
		if a % 2 == 0:
			return 0
		else:
			return 1
	elif a > b:
		if a % 2 == 0 and b % 2 == 0:
			return 0
		elif a % 2 != 0 and b % 2 != 0:
			return 0
		elif a % 2 == 0 and b % 2 != 0:
			return 1
		elif a % 2 != 0 and b % 2 == 0:
			return 1
	elif a < b:
		return b - a
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print(solve(a, b))


import sys
T = int(sys.stdin.readline().strip())
for t in range(0, T):
	(n, k) = list(map(int, sys.stdin.readline().strip().split()))
	if n >= k:
		if (n + k) % 2 == 1:
			print(1)
		else:
			print(0)
	else:
		print(k - n)


T = int(input())
arr = []
for i in range(T):
	(n, k) = list(map(int, input().split()))
	d = 0
	if n < k:
		d = k - n
	elif n % 2 == k % 2:
		d += 0
	else:
		d += 1
	arr.append(d)
	d = 0
print(*arr, sep='\n')


import sys

def main():
	t = Iint()
	for _ in range(t):
		(n, k) = Imap()
		if n >= k and (n - k) % 2 == 0:
			print(0)
		elif n >= k and (n - k) % 2 == 1:
			print(1)
		elif n < k:
			print(k - n)
FIO = 10

def I():
	return input()

def Iint():
	return int(input())

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

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

def Plist(li, s=' '):
	print(s.join(map(str, li)))
en = enumerate

def answer_debug(*args):
	print('\x1b[31m', *args, '\x1b[0m', file=sys.stderr)

def debug(*args):
	print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)
if not FIO:
	if __name__ == '__main__':
		main()
		exit()
else:
	from io import BytesIO, IOBase
	import os
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')
main()


t = int(input())
for _ in range(t):
	(n, k) = (int(x) for x in input().split())
	if n < k:
		print(k - n)
	elif n % 2 == k % 2:
		print(0)
	else:
		print(1)


t = int(input())
for test in range(t):
	(n, k) = [int(x) for x in input().split()]
	if k >= n:
		ans = abs(n - k)
		print(ans)
	elif n % 2 != 0:
		if k % 2 != 0:
			print(0)
		else:
			print(1)
	elif k % 2 == 0:
		print(0)
	else:
		print(1)


def answer(n, k):
	if n <= k:
		return k - n
	elif n & 1 == k & 1:
		return 0
	else:
		return 1
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	print(answer(n, k))


import sys
from functools import reduce
from collections import Counter
import time
import datetime
from math import sqrt, gcd

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

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

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

def mips():
	return map(str, sys.stdin.readline().split())

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

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.append(arr)
	return lst

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

def minJumps(arr, n):
	jumps = [0 for i in range(n)]
	if n == 0 or arr[0] == 0:
		return float('inf')
	jumps[0] = 0
	for i in range(1, n):
		jumps[i] = float('inf')
		for j in range(i):
			if i <= j + arr[j] and jumps[j] != float('inf'):
				jumps[i] = min(jumps[i], jumps[j] + 1)
				break
	return jumps[n - 1]

def dic(arr):
	return Counter(arr)

def check_prime(n):
	if n < 2:
		return False
	for i in range(2, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True
n = ip()
while n:
	n -= 1
	(m, k) = mip()
	if m == k:
		print(0)
	elif k > m:
		print(k - m)
	elif m % 2 == 0 and k == 0:
		print(0)
	elif m % 2 != 0 and k == 0:
		print(1)
	elif m % 2 == 0 and k % 2 == 0:
		print(0)
	elif m % 2 != 0 and k % 2 != 0:
		print(0)
	else:
		print(1)


from math import log2, ceil, floor
from collections import defaultdict, OrderedDict, Counter, deque
from heapq import heappush, heappop, heapify, nlargest, nsmallest
import re

def inp():
	return input()

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

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

def int_inp():
	return int(input())

def float_int():
	return float(input())

def isprime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
for _ in range(int_inp()):
	(n, k) = map_inp()
	if n < k:
		print(k - n)
	elif n == k:
		print(0)
	elif k % 2 == 0:
		if n % 2 != 0:
			print(1)
		else:
			print(0)
	elif n % 2 != 0:
		print(0)
	else:
		print(1)


T = int(input().strip())
for i in range(T):
	(n, k) = list(map(lambda x: int(x), input().strip().split(' ')))
	if n == k or n == -k:
		print(0)
	elif (n + k) % 2 == 0 and n >= k:
		print(0)
	elif n < k:
		print(k - n)
	else:
		print(1)


def main():
	t = int(input())
	for _ in range(t):
		print(case())

def case():
	(n, k) = map(int, input().split())
	if k >= n:
		return k - n
	elif (k + n) % 2:
		return 1
	else:
		return 0
	return
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	res = max(0, k - n)
	if res == 0 and n % 2 != k % 2:
		print(1)
	else:
		print(res)


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

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

def si():
	return input()

def mi():
	return map(int, input().split())
for _ in range(ii()):
	(n, k) = mi()
	if k == 0:
		if n % 2 == 0:
			print(0)
		else:
			print(1)
	elif k > n:
		print(k - n)
	elif k == n:
		print(0)
	elif k < n:
		if n % 2 == 0:
			if k % 2 == 0:
				print(0)
			else:
				print(1)
		elif k % 2 != 0:
			print(0)
		else:
			print(1)


import sys

def get_single_int():
	return int(sys.stdin.readline().strip())

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

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
for i in range(get_single_int()):
	(n, k) = get_ints()
	if n <= k:
		print(k - n)
		continue
	elif (k + n) % 2 == 0:
		print(0)
	else:
		print(1)


t = int(input())
i = 1
while True:
	if i > t:
		break
	(n, k) = map(int, input().split())
	m = n - k
	if m < 0:
		print(abs(m))
	elif m % 2 == 0:
		print(0)
	else:
		print(1)
	i = i + 1


T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	ans = 0
	(N, K) = (n % 2, k % 2)
	if N == 1 and K == 1:
		if k <= n:
			ans += 0
		else:
			ans += k - n
	elif N == 0 and K == 0:
		if k <= n:
			ans += 0
		else:
			ans += k - n
	elif k < n:
		ans += 1
	else:
		ans += k - n
	print(ans)


t = int(input())
for tc in range(t):
	line = input().split()
	(n, k) = (int(line[0]), int(line[1]))
	steps = 0
	if n > k:
		if k % 2 == 0:
			if n % 2 == 0:
				steps = 0
			else:
				steps = 1
		elif n % 2 != 0:
			steps = 0
		else:
			steps = 1
	else:
		steps = k - n
		n = k
		if k % 2 == 0:
			if n % 2 == 0:
				pass
			else:
				steps += 1
		elif n % 2 != 0:
			pass
		else:
			steps += 1
	print(steps)


for _ in range(int(input())):
	(a, k) = map(int, input().split())
	if a < k:
		print(k - a)
	else:
		print('0' if k & 1 == a & 1 else '1')


firstIn = int(input())
results = []
for n in range(firstIn):
	inp = input()
	(astr, kstr) = inp.split()
	a = int(astr)
	k = int(kstr)
	if a < k:
		results.append(k - a)
	elif a % 2 == k % 2:
		results.append(0)
	else:
		results.append(1)
for result in results:
	print(result)


from sys import stdin, stdout, setrecursionlimit

class Tail_Recursion_Optimization:

	def __init__(self, RECURSION_LIMIT, STACK_SIZE):
		setrecursionlimit(RECURSION_LIMIT)
		threading.stack_size(STACK_SIZE)
		return None

class SOLVE:

	def solve(self):
		R = stdin.readline
		W = stdout.write
		ans = []
		for i in range(int(R())):
			(n, k) = map(int, R().split())
			if k <= n:
				if n % 2:
					ans.append(['1', '0'][k % 2])
				else:
					ans.append(['0', '1'][k % 2])
			else:
				ans.append(str(k - n))
		W('\n'.join(ans))
		return 0

def main():
	s = SOLVE()
	s.solve()
main()


t = int(input())
while t:
	(a, k) = map(int, input().split())
	if k == a:
		print(0)
	if k > a:
		print(k - a)
	elif k < a and (k + a) % 2 == 1:
		print(1)
	elif k < a and (k + a) % 2 == 0:
		print(0)
	t -= 1


import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(abs(n - k))
	elif n % 2 == k % 2:
		print(0)
	else:
		print(1)


import sys
import string
import math
import heapq
from collections import defaultdict
from functools import lru_cache
from collections import Counter
from fractions import Fraction

def mi(s):
	return map(int, s.strip().split())

def lmi(s):
	return list(mi(s))

def tmi(s):
	return tuple(mi(s))

def mf(f, s):
	return map(f, s)

def lmf(f, s):
	return list(mf(f, s))

def js(lst):
	return ' '.join((str(d) for d in lst))

def jsns(lst):
	return ''.join((str(d) for d in lst))

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

def linesp():
	return line().split()

def iline():
	return int(line())

def mat(n):
	matr = []
	for _ in range(n):
		matr.append(linesp())
	return matr

def matns(n):
	mat = []
	for _ in range(n):
		mat.append([c for c in line()])
	return mat

def mati(n):
	mat = []
	for _ in range(n):
		mat.append(lmi(line()))
	return mat

def pmat(mat):
	for row in mat:
		print(js(row))

def solve(a, k):
	work = abs(k - a)
	if a == 0 and k == 0:
		work = 0
	elif a > 0 and k == 0:
		if a % 2 == 0:
			work = 0
		else:
			work = min(1, work)
	elif a > 0 and k > 0 and (k < a):
		if (a - k) % 2 == 0:
			work = 0
		else:
			work = min(work, 1)
	elif a > 0 and k == a:
		work = 0
	print(work)

def main():
	t = iline()
	for _ in range(t):
		solve(*mi(line()))
main()


from sys import stdin, stdout
test = int(stdin.readline())
for _ in range(test):
	(n, k) = map(int, stdin.readline().split())
	if n <= k:
		print(k - n)
	else:
		(a, b) = (n & 1, k & 1)
		if a == b:
			print(0)
		else:
			print(1)


import collections

def sort(key):
	return len(key[1])

def solve(p, k):
	if k > p:
		return k - p
	elif p > k and p % 2 == 1 and (k % 2 == 0):
		return 1
	elif p > k and p % 2 == 0 and (k % 2 == 1):
		return 1
	return 0
ans = []
n = int(input())
for i in range(n):
	(p, k) = map(int, input().split())
	print(solve(p, k))
for i in ans:
	print(i)


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def solve():
	(n, k) = map(int, inputi().split())
	if n == k:
		print(0)
		return
	x = max(0, k - n)
	b2 = x - k + n
	if b2 % 2 == 1:
		x += 1
	print(x)

def main():
	t = int(inputi())
	for _ in range(t):
		solve()
main()


n1 = int(input())
for x in range(n1):
	a = list(map(int, input().split()))
	n = a[0]
	k = a[-1]
	if n % 2 == 0 and k == 0:
		print(0)
	elif n % 2 != 0 and k == 0:
		print(1)
	elif n == k:
		print(0)
	elif n < k:
		print(abs(n - k))
	elif n >= k and n % 2 == 0 and (k % 2 == 0):
		print(0)
	elif n >= k and n % 2 == 0 and (k % 2 != 0):
		print(1)
	elif n >= k and n % 2 != 0 and (k == 0):
		print(1)
	elif n >= k and n % 2 != 0 and (k % 2 != 0):
		print(0)
	elif n >= k and n % 2 != 0 and (k % 2 == 0):
		print(1)
	else:
		print(0)


for i in range(int(input())):
	(a, k) = [int(i) for i in input().split()]
	if a == k:
		print(0)
	elif k == 0 and a % 2 == 0:
		print(0)
	elif k == 0 and a % 2:
		print(1)
	elif k <= a:
		if k % 2:
			if a % 2 == 0:
				print(1)
			else:
				print(0)
		elif a % 2 == 1:
			print(1)
		else:
			print(0)
	else:
		print(abs(a - k))


t = int(input())
for i in range(t):
	(a, diff) = map(int, input().split())
	if diff > a:
		print(diff - a)
	elif diff % 2 == 0 and a % 2 == 1 or (diff % 2 == 1 and a % 2 == 0):
		print(1)
	else:
		print(0)


t = int(input())
while t > 0:
	(n, k) = [int(x) for x in input().split()]
	if n == k:
		print('0')
	elif n < k:
		print(k - n)
	elif n % 2 == 0 and k % 2 == 0:
		print('0')
	elif n % 2 != 0 and k % 2 != 0:
		print('0')
	else:
		print('1')
	t -= 1


for _ in range(int(input())):
	X = list(map(int, input().split()))
	(n, m) = (int(X[0]), int(X[1]))
	if m >= n:
		ans = abs(m - n)
	elif m % 2 == 0 and n % 2 == 0 or (m % 2 != 0 and n % 2 != 0):
		ans = 0
	else:
		ans = 1
	print(ans)


import sys
for _ in range(int(sys.stdin.readline().rstrip())):
	(n, k) = list(map(int, sys.stdin.readline().rstrip().split()))
	re = k - n
	if re < 0:
		if n % 2 == k % 2:
			re = 0
		else:
			re = 1
	print(re)


test_cases = int(input())
for test_case in range(test_cases):
	(n, k) = list(map(int, input().split()))
	if n >= k:
		if (n + k) % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		print(k - n)


import io, os
import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n >= k:
		if n - k & 1:
			print(1)
		else:
			print(0)
	else:
		print(k - n)


for s in [*open(0)][1:]:
	(n, k) = map(int, s.split())
	print([n - k & 1, k - n][n < k])


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ans = max(0, k - n)
	n += ans
	if n % 2 == 0:
		if k % 2 == 1:
			ans += 1
	elif k % 2 == 0:
		ans += 1
	print(ans)


res = ''
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = 0
	if k == 0:
		if n % 2:
			l = 1
	elif k > n:
		l = k - n
	elif k % 2 != n % 2:
		l = 1
	res += f'{l}\n'
print(res)


from math import *
import sys
cin = lambda : sys.stdin.readline().strip()
cout = sys.stdout.write

def main(tc):
	(n, k) = map(int, cin().split(' '))
	ans = max(n, k) - min(n, k)
	cout(f'{(ans % 2 if k < n else ans)}\n')
for i in range(int(cin())):
	main(i + 1)


testcase = int(input())
for test in range(testcase):
	(A, k) = map(int, input().split())
	if A < k:
		res = k - A
	elif A % 2 == 0 and k % 2 == 0 or (A % 2 == 1 and k % 2 == 1):
		res = 0
	else:
		res = 1
	print(res)


t = int(input())
lista = []
for i in range(t):
	(n, k) = [int(q) for q in input().split()]
	if k > n:
		lista.append(k - n)
	elif abs(k - n) % 2 == 1:
		lista.append(1)
	else:
		lista.append(0)
for i in lista:
	print(i)


try:
	for i1 in range(int(input())):
		(n, k) = map(int, input().split())
		if k >= n:
			print(k - n)
		elif n % 2 == 0 and k % 2 == 0:
			print(0)
		elif n % 2 != 0 and k % 2 == 0:
			print(1)
		elif n % 2 == 0 and k % 2 != 0:
			print(1)
		elif n % 2 != 0 and k % 2 != 0:
			print(0)
except:
	pass


case = int(input())
lst = []
for i in range(case):
	lst.append(list(map(int, input().split(' '))))
for i in lst:
	if i[1] < i[0]:
		if i[1] % 2 == 0 and i[0] % 2 == 0 or (i[1] % 2 == 1 and i[0] % 2 == 1):
			print(0)
		else:
			print(1)
	else:
		print(abs(i[0] - i[1]))


for i in range(int(input())):
	(n, k) = [int(num) for num in input().split()]
	if k >= n:
		print(k - n)
	elif (n + k) % 2 == 0:
		print(0)
	else:
		print(1)


for _ in range(int(input())):
	(x, y) = list(map(int, input().split()))
	if y > x:
		print(y - x)
	elif x % 2 == 0:
		if y % 2 == 0:
			print('0')
		else:
			print('1')
	elif y % 2 == 0:
		print('1')
	else:
		print('0')


t = int(input(''))
i = 0
while i < t:
	i += 1
	line = input('').split()
	n = int(line[0])
	k = int(line[1])
	ans = k - n
	if ans < 0:
		ans = n & 1 == k & 1
		if ans:
			print(0)
		else:
			print(1)
	else:
		print(ans)


tc = int(input())
for i in range(tc):
	(a, d) = (int(j) for j in input().split())
	if a % 2 == d % 2:
		if d <= a:
			print('0')
		else:
			print(abs(d - a))
	elif d <= a:
		print('1')
	else:
		print(abs(d - a))


import sys
input = sys.stdin.readline

def solve():
	(n, k) = list(map(int, input().split()))
	if k > n:
		print(k - n)
	elif k % 2 == n % 2:
		print(0)
	else:
		print(1)
t = int(input())
for _ in range(t):
	solve()


import sys
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k > n:
		print(k - n)
	else:
		print((n - k) % 2)


import sys
input = sys.stdin.readline
t = int(input())
for t1 in range(t):
	(n, k) = list(map(int, input().split(' ')))
	if n >= k:
		if (n + k) % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		print(k - n)


import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
input = sys.stdin.readline

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
for _ in range(inin()):
	(n, k) = cin()
	if k <= n:
		ans = 0
	else:
		ans = k - n
		n = k
	if k % 2 == n % 2:
		print(ans)
	else:
		print(ans + 1)


a = int(input())
for x in range(a):
	(b, c) = map(int, input().split())
	if c > b:
		print(c - b)
	elif (b - c) % 2 == 0:
		print(0)
	else:
		print(1)


import sys
import os
import math
import copy
from math import gcd
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from itertools import accumulate

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

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

def Lstr():
	return list(sys.stdin.readline().strip())

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

def Mstr():
	return map(str, sys.stdin.readline().strip().split())

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

def Hash():
	return dict()

def Mod():
	return 1000000007

def Ncr(n, r, p):
	return fact[n] * (ifact[r] * ifact[n - r] % p) % p

def Most_frequent(list):
	return max(set(list), key=list.count)

def Mat2x2(n):
	return [List() for _ in range(n)]

def Lcm(x, y):
	return x * y // gcd(x, y)

def dtob(n):
	return bin(n).replace('0b', '')

def btod(n):
	return int(n, 2)

def common(l1, l2):
	return set(l1).intersection(l2)

def solution():
	for _ in range(Int()):
		(n, k) = Mint()
		if k >= n:
			print(k - n)
		elif (n - k) % 2 == 0:
			print(0)
		else:
			print(1)
solution()


import sys

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

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

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

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

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

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math
from collections import defaultdict
for _ in range(ri()):
	(n, k) = ria()
	if k < n:
		if n % 2 == 0:
			if k % 2:
				print(1)
			else:
				print(0)
		elif k % 2:
			print(0)
		else:
			print(1)
	elif n == k:
		print(0)
	else:
		print(abs(k - n))


import sys
import math
import heapq
import collections
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')

def printspace(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer(' ')

def inputnum():
	return int(input())

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

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

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

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	(n, k) = inputnums()
	if k > n:
		print(k - n)
	elif (n + k) % 2 == 1:
		print(1)
	else:
		print(0)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	b = 0
	if n < k:
		print(k - n)
	if n >= k:
		if n % 2 == k % 2:
			print('0')
		else:
			print('1')


t = int(input())
while t:
	t -= 1
	[n, k] = [int(val) for val in input().split()]
	if k > n:
		print(k - n)
	elif ((k & 1) + (n & 1)) % 2:
		print(1)
	else:
		print(0)


for _ in range(int(input())):
	(a, k) = [int(x) for x in input().split()]
	if k >= a:
		print(k - a)
	elif (a - k) % 2:
		print(1)
	else:
		print(0)


for _ in range(int(input())):
	(a, d) = map(int, input().split())
	if a <= d:
		print(d - a)
	elif a % 2 == 0 and d % 2 == 0 or (a % 2 != 0 and d % 2 != 0):
		print(0)
	else:
		print(1)


t = int(input())
arr = []
cnt = []
for i in range(t):
	s = input().split(' ')
	arr.append([int(s[0]), int(s[1])])
	if arr[i][0] >= arr[i][1]:
		if (arr[i][0] - arr[i][1]) % 2 == 0:
			cnt.append(0)
		else:
			cnt.append(1)
	else:
		cnt.append(arr[i][1] - arr[i][0])
for i in cnt:
	print(i)


output = []
for i in range(int(input())):
	a = input().split()
	b = int(a[0])
	c = int(a[1])
	if c >= b:
		output.append(c - b)
	elif b % 2 == 0 and c % 2 == 0:
		output.append(0)
	elif b % 2 == 1 and c % 2 == 1:
		output.append(0)
	else:
		output.append(1)
print('\n'.join([str(i) for i in output]))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	num = 0
	if k > n + num:
		num = k - n
	while (n + num - k) % 2 != 0:
		num += 1
	print(num)


def main():
	t = int(input())
	for i in range(t):
		(n, k) = [int(x) for x in input().split(' ')]
		if k >= n:
			print(k - n)
		elif (n - k) % 2 == 1:
			print(1)
		else:
			print(0)
main()


t = int(input())
myList = []
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	if n > k:
		if (n - k) % 2 == 0:
			myList.append(0)
		else:
			myList.append(1)
	else:
		myList.append(k - n)
for elem in myList:
	print(elem)


T = lambda : range(int(input()))
A = lambda : list(map(int, input().split()))
for _ in T():
	(N, K) = A()
	if K >= N:
		print(K - N)
	elif (K + N) / 2 == (K + N) // 2:
		print(0)
	else:
		print(1)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = max(k - n, 0)
	if a == 0 and (n - k) % 2 == 1:
		a += 1
	ans = min([abs(n - k), a])
	print(ans)


import random

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

def lcm(a, b):
	return a * b / gcd(a, b)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n >= k:
		print((n + k) % 2)
	else:
		print(k - n)


for i in range(int(input())):
	(a, k) = input().split(' ')
	a = int(a)
	k = int(k)
	if a >= k:
		print((a - k) % 2)
	else:
		print(k - a)


try:
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		s = 0
		if k == 0:
			if n % 2 == 1:
				s = 1
		elif k < n:
			if k % 2 == 0 and n % 2 == 0 or (k % 2 == 1 and n % 2 == 1):
				s = 0
			else:
				s = 1
		elif k == n:
			s = 0
		else:
			s = abs(n - k)
		print(s)
except:
	pass


import sys
from math import *
input = sys.stdin.readline

def solve(n, k):
	if n < k:
		print(k - n)
	else:
		print(int((n - k) % 2))
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	solve(n, k)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(n, k) = I()
	an = 0
	if k > n:
		an = k - n
	else:
		an = 1 if k % 2 != n % 2 else 0
	print(an)


import sys, math as mt
import heapq as hp
import collections as cc
import math as mt
import itertools as it
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n, k) = I()
	if k > n:
		print(abs(n - k))
	else:
		print(0 if n % 2 == k % 2 else 1)


t = int(input())
for i in range(t):
	step = 0
	(n, k) = [int(x) for x in input().split()]
	if k >= n:
		print(k - n)
	else:
		print((n - k) % 2)


def solve(n, k):
	d = k - n
	if k > n:
		return abs(k - n)
	elif n == k:
		return 0
	elif n > k:
		(ne, ke) = (False, False)
		if n % 2 == 0:
			ne = True
		if k % 2 == 0:
			ke = True
		if ne and ke:
			return 0
		elif ne == False and ke == False:
			return 0
		else:
			return 1
for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	ans = solve(n, k)
	print(ans)


t = int(input())
for it in range(t):
	(n, k) = [int(i) for i in input().split()]
	if n >= k:
		print(0 if n % 2 == k % 2 else 1)
	else:
		print(k - n)


import sys
input = sys.stdin.readline
T = int(input())
for testcase in range(T):
	(n, k) = map(int, input().split())
	if k <= n:
		if n % 2 == k % 2:
			print(0)
		else:
			print(1)
	else:
		print(k - n)


t = int(input())
while t:
	t = t - 1
	(n, k) = map(int, input().split())
	dis = (k + n) // 2
	if n == k:
		print(0)
	elif k > n:
		print(k - n)
	elif (n + k) % 2 == 0:
		print(0)
	elif (n + k) % 2 == 1:
		print(1)


import sys
read = lambda : sys.stdin.readline().strip()
for _ in range(int(read())):
	(n, k) = map(int, read().split())
	if n == k:
		print(0)
		continue
	x = (n - k) / 2
	if x < 0:
		print(k - n)
		continue
	if int(x) != x:
		print(1)
		continue
	print(0)


for i in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if n < k:
		print(k - n)
	elif n == k:
		print(0)
	elif n > k:
		f = (n - k) / 2
		co = 0
		while True:
			f = (n - k) / 2
			if f == int(f):
				break
			n += 1
			co += 1
		print(co)


x = int(input())
for i in range(x):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	if (n % 2 == 0 and k % 2 == 0 or (n % 2 == 1 and k % 2 == 1)) and k <= n:
		print(0)
	elif k < n:
		print(1)
	else:
		print(abs(n - k))


t = int(input())
steps = []
for _ in range(t):
	(n, k) = map(int, input().split())
	if k > n:
		s = k - n
	elif k == n:
		s = 0
	elif (n + k) % 2 == 0:
		s = 0
	else:
		s = 1
	steps.append(s)
for j in steps:
	print(j)


T = int(input())
results = []
for ttt in range(T):
	res = 0
	x = [int(item) for item in input().split()]
	if x[0] < x[1]:
		results.append(x[1] - x[0])
	elif x[0] % 2 == x[1] % 2:
		results.append(0)
	else:
		results.append(1)
print(*results, sep='\n')


t = int(input())
for z in range(t):
	(n, k) = map(int, input().split())
	result = 0
	if n < k:
		result += k - n
		n = k
	if (n - k) % 2 == 1:
		result += 1
	print(result)


from sys import stdin
input = stdin.readline
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	if n <= k:
		print(k - n)
	elif n % 2 == 0 and k % 2 == 0:
		print(0)
	elif n % 2 == 1 and k % 2 == 1:
		print(0)
	else:
		print(1)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	ans = 0
	if k > n:
		print(abs(n - k))
	elif k % 2 == 0 and n % 2 == 0:
		print(0)
	elif k % 2 == 0 and n % 2 == 1:
		print(1)
	elif k % 2 == 1 and n % 2 == 1:
		print(0)
	elif k % 2 == 1 and n % 2 == 0:
		print(1)


t = int(input())
for i in range(t):
	(a, k) = map(int, input().split())
	if k == a:
		print(0)
	elif k > a:
		print(k - a)
	elif k == 0 and a == 1:
		print(1)
	elif k == 0 and a % 2 == 0:
		print(0)
	elif k == 0 and a % 2 != 0:
		print(1)
	elif k % 2 == 0 and a % 2 == 0:
		print(0)
	elif k % 2 == 0 and a % 2 != 0:
		print(1)
	elif k % 2 != 0 and a % 2 == 0:
		print(1)
	elif k % 2 != 0 and a % 2 != 0:
		print(0)


cases = int(input())
for i in range(cases):
	line = input().split(' ')
	n = int(line[0])
	k = int(line[1])
	if n < k:
		print(k - n)
	else:
		b = (n - k) / 2
		if n % 2 == k % 2 == 0:
			print(0)
		elif n % 2 == k % 2 == 1:
			print(0)
		else:
			print(1)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	print(max(k - n, n + k & 1))


from queue import Queue

def rn():
	a = int(input())
	return a

def rl():
	a = list(map(int, input().split()))
	return a
for _ in range(rn()):
	[a, k] = rl()
	ans = 0
	if k <= a:
		if (k + a) % 2 == 0:
			ans = 0
		else:
			ans = 1
	else:
		ans = k - a
		a = k
		if (k + a) % 2 != 0:
			ans += 1
	print(ans)


def solution(n, k):
	return k - n if n < k else (n - k) % 2
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split(' '))
	print(solution(n, k))


t = int(input())
while t != 0:
	t -= 1
	(x, k) = map(int, input().split())
	if x <= k:
		print(abs(x - k))
	elif x % 2 == 0:
		if k == 0:
			print(k)
		elif k % 2 != 0:
			print(1)
		else:
			print(0)
	elif k == 0:
		print(1)
	elif k % 2 != 0:
		print(0)
	else:
		print(1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	x = 0
	if n < k:
		x = k - n
		n = k
	if n + k & 1:
		x += 1
	print(x)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
t = ip()
for _ in range(t):
	(n, k) = inp()
	if k <= n:
		if n & 1 == 1:
			if k & 1 == 1:
				ans = 0
			else:
				ans = 1
		elif k & 1 == 1:
			ans = 1
		else:
			ans = 0
	else:
		ans = k - n
	print(ans)


T = int(input())
while T:
	(n, k) = map(int, input().split())
	if k >= n:
		print(k - n)
	else:
		print((n - k) % 2)
	T = T - 1


import io
import os
import sys
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def prdbg(*args, **kwargs):
	print(*args, **kwargs, file=sys.stderr)
	pass

def get_str():
	return input().decode().strip()

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

def oint():
	return int(input())
t = oint()
for _ in range(t):
	(n, k) = rint()
	if n % 2 == 0:
		if k <= n:
			if k % 2 == 0:
				print(0)
			else:
				print(1)
		else:
			print(k - n)
	elif k <= n:
		if k % 2:
			print(0)
		else:
			print(1)
	else:
		print(k - n)


g = 0
for t in range(int(input())):
	(n, k) = [int(h) for h in input().split()]
	if k > n:
		print(k - n)
	elif n % 2 == k % 2:
		print(0)
	else:
		print(1)


tests = int(input())

def countSteps(n, k):
	steps = 0
	if n < k:
		steps = k - n
		n = k
	while (n + k) % 2 != 0:
		steps = steps + 1
		n += 1
	return steps
for i in range(tests):
	(n, k) = map(int, input().split())
	steps = countSteps(n, k)
	print(steps)


n = int(input())
res = []
for i in range(n):
	P = list(map(int, input().split()))
	if P[1] == 0:
		if P[0] % 2 == 0:
			res.append(0)
		else:
			res.append(1)
	elif P[1] >= P[0]:
		res.append(P[1] - P[0])
	elif (P[0] - P[1]) % 2 == 0:
		res.append(0)
	else:
		t = (int((P[0] - P[1]) / 2) + 1) * 2 + P[1] - P[0]
		res.append(t)
for k in res:
	print(k)


import sys
from collections import defaultdict as dd
from collections import deque
from functools import *
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def inc(d, c):
	d[c] = d[c] + 1 if c in d else 1

def bo(i):
	return ord(i) - ord('A')

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

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

def gh():
	sys.stdout.flush()

def isvalid(i, j):
	return 0 <= i < n and 0 <= j < n

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = fi()
while t > 0:
	t -= 1
	(n, k) = mi()
	if k <= n:
		if k % 2 != n % 2:
			print(1)
		else:
			print(0)
	else:
		print(k - n)


from sys import stdin, stdout
from math import gcd, sqrt, factorial
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 0 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	(n, k) = R()
	if k >= n:
		print(k - n)
	elif n % 2 != k % 2:
		print(1)
	else:
		print(0)


import sys
input = sys.stdin.buffer.readline
inin = lambda : int(input())
inar = lambda : list(map(int, input().split()))
inst = lambda : input().decode().rstrip('\n\r')
_T_ = inin()
for _t_ in range(_T_):
	(n, k) = inar()
	if k > n:
		print(k - n)
	elif k % 2:
		if n % 2:
			print(0)
		else:
			print(1)
	elif n % 2:
		print(1)
	else:
		print(0)


answer = []
for t in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if n < k:
		answer.append(str(k - n))
	elif n % 2 == k % 2:
		answer.append('0')
	else:
		answer.append('1')
print('\n'.join(answer))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	n1 = n + 0
	n2 = n + 0
	c1 = 0
	c2 = 0
	c = 0
	if (k + n1) // 2 < n:
		while k + n1 < 0 or (k + n1) % 2 != 0:
			c += 1
			n1 += 1
	else:
		c = c + abs(k - n)
	print(c)


import sys

def solve(n, k):
	if n <= k:
		ans = k - n
	else:
		ans = (n - k) % 2
	print(ans)
	sys.stdout.flush()
T = int(input())
for t in range(T):
	(n, k) = [int(it) for it in input().split(' ')]
	solve(n, k)


import sys

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

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
for _ in range(INT()):
	(N, K) = MAP()
	if N <= K:
		print(abs(N - K))
	elif N % 2 == K % 2:
		print(0)
	else:
		print(1)


for test in range(int(input())):
	(O, K) = map(int, input().strip().split(' '))
	if K > O:
		print(K - O)
	else:
		j = int((O + K) / 2)
		if abs(j - 0 - (O - j)) == K:
			print(0)
		else:
			print(1)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(k - n)
	else:
		a = n - k
		print(a % 2)


from sys import stdin
import math
for _ in range(int(input())):
	(n, k) = map(int, stdin.readline().rstrip().split(' '))
	if n > k:
		if (n - k) % 2:
			print(1)
		else:
			print(0)
	else:
		print(k - n)


import sys
from collections import defaultdict as dd
from collections import Counter as ccd
from itertools import permutations as pp
from itertools import combinations as cc
from random import randint as rd
from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq as hq
import math
mod = pow(10, 9) + 7

def inp(flag=0):
	if flag == 0:
		return list(map(int, input().strip().split(' ')))
	elif flag == 1:
		return int(input())
	else:
		return input().strip()

def inp_fast(flag=0):
	if flag == 0:
		return list(map(int, sys.stdin.readline().split()))
	elif flag == 1:
		return int(sys.stdin.readline())
	else:
		return sys.stdin.readline()
t = inp(1)
while t:
	t -= 1
	(n, k) = inp(0)
	if n > k:
		if n % 2 == k % 2:
			print(0)
		else:
			print(1)
	else:
		print(k - n)


from collections import defaultdict
import sys
import math

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

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	(n, k) = get_ints()
	if n > k:
		if k % 2:
			if n % 2:
				print(0)
			else:
				print(1)
		elif n % 2:
			print(1)
		else:
			print(0)
	else:
		print(abs(n - k))


def solve():
	(a, k) = list(map(int, input().split()))
	if a <= k:
		print(k - a)
		return
	if a % 2 == k % 2:
		print(0)
		return
	print(1)
	return
T = int(input())
for _ in range(T):
	solve()


from math import fabs
t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	if (n - m) % 2 == 1:
		if n >= m:
			print(1)
		else:
			print(m - n)
	elif n >= m:
		print(0)
	else:
		print(m - n)


def main():
	for _ in range(int(input())):
		(n, k) = list(map(int, input().split()))
		if k <= n:
			if k % 2 == n % 2:
				print(0)
			else:
				print(1)
		else:
			print(k - n)
main()


import math

def dtb(n):
	return bin(n).replace('0b', '')

def btd(n):
	return int(n, 2)
t = int(input())
for k in range(t):
	(n, m) = map(int, input().split())
	if n < m:
		print(m - n)
	elif m % 2 == n % 2:
		print(0)
	else:
		print(1)


import sys
import math
for _ in range(int(input())):
	(a, k) = map(int, input().split())
	if a <= k:
		print(k - a)
	elif (a - k) % 2 == 1:
		print(1)
	else:
		print(0)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if b > a:
		print(b - a)
	else:
		print((b - a) % 2)


for _ in range(int(input())):
	ans = 0
	(n, k) = list(map(int, input().split()))
	if k >= n:
		ans = k - n
	else:
		while (n - k) % 2 != 0:
			ans += 1
			n += 1
	print(ans)


t = int(input())
for i in range(0, t):
	(n, k) = list(map(int, input().rstrip().split()))
	if (n + k) % 2 == 0:
		if k - n > 0:
			print(k - n)
		else:
			print(0)
	elif k - (n + 1) > 0:
		print(k - n)
	else:
		print(1)


from functools import reduce
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

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

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def inn():
	return int(input())
mo = 1000000007
for _ in range(int(input())):
	(n, k) = value()
	if n == k:
		print(0)
	elif k > n:
		print(k - n)
	elif n % 2 == 1:
		if k % 2 == 0:
			print(1)
		else:
			print(0)
	elif k % 2 == 0:
		print(0)
	else:
		print(1)


import os
t = int(input().rstrip())
for _ in range(t):
	(n, k) = list(map(int, input().rstrip().split()))
	if n < k:
		print(k - n)
	elif n % 2 == k % 2:
		print(0)
	else:
		print(1)


import sys, math
input = sys.stdin.readline
t = int(input())
for r in range(t):
	(n, k) = map(int, input().split())
	if k <= n:
		if (n - k) % 2 != 0:
			print(1)
		else:
			print(0)
	else:
		print(abs(n - k))


def get_step(n, k):
	if k == n:
		step = 0
	elif n > k:
		if (n + k) % 2 == 0:
			step = 0
		elif (n + k) % 2 == 1:
			step = 1
	elif n < k:
		step = k - n
	return step
t = int(input())
for case in range(t):
	(n, k) = (int(i) for i in input().split())
	print(get_step(n, k))


from sys import stdin
import math
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	(n, k) = [int(x) for x in inp().split()]
	if n < k:
		print(k - n)
	elif n % 2 != k % 2:
		print(1)
	else:
		print(0)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	dif = 0 if n > k else k - n
	if k % 2 != n % 2 and dif == 0:
		dif += 1
	print(abs(dif))


T = int(input().strip())
while T > 0:
	(n, k) = [int(x) for x in input().strip().split()]
	if n == k:
		print(0)
	elif k < n and abs(n - k) % 2 == 0:
		print(0)
	elif k < n:
		print(1)
	else:
		print(abs(n - k))
	T -= 1


def squareRoot(number, precision):
	start = 0
	(end, ans) = (number, 1)
	while start <= end:
		mid = int((start + end) / 2)
		print(mid)
		if mid * mid == number:
			ans = mid
			print('hi')
			break
		if mid * mid < number:
			start = mid + 1
		else:
			end = mid - 1
	increment = 0.1
	print(str(ans) + 'hhee')
	for i in range(0, precision):
		while ans * ans <= number:
			ans += increment
		ans = ans - increment
		increment = increment / 10
	return ans
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if k <= n:
		if n % 2 == 0 and k % 2 == 0:
			print(0)
		elif n % 2 != 0 and k % 2 != 0:
			print(0)
		else:
			print(1)
	else:
		m = k - n
		k += k - n
		if n % 2 == 0 and k % 2 == 0:
			print(m)
		elif n % 2 != 0 and k % 2 != 0:
			print(m)
		else:
			print(1 + m)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n & 1 == 1:
		if k < n:
			if k & 1 == 1:
				steps = 0
			else:
				steps = 1
		else:
			steps = abs(k - n)
	elif k < n:
		if k & 1 == 0:
			steps = 0
		else:
			steps = 1
	else:
		steps = abs(k - n)
	print(steps)


from sys import stdin

def solve(n, k):
	if k <= n:
		if n % 2 == 0:
			if k % 2 == 0:
				return 0
			else:
				return 1
		elif k % 2 == 1:
			return 0
		else:
			return 1
	else:
		return k - n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(solve(n, k))


T = int(input())
while T:
	(N, K) = map(int, input().split())
	if K > N:
		print(K - N)
	elif K == N:
		print(0)
	elif N % 2 == K % 2:
		print(0)
	else:
		print(1)
	T -= 1


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(m,) = I()
while m:
	m -= 1
	(n, k) = I()
	if n < k:
		print(k - n)
	elif k == n:
		print(0)
	elif (n + k) % 2:
		print(1)
	else:
		print(0)


t = int(input())
while t > 0:
	n = 2
	ls1 = [0] * n
	ls1 = list(map(int, input().split()))
	a = ls1[0]
	d = ls1[1]
	num = a
	if d > a:
		res = d - a
	elif d == a:
		res = 0
	elif d < a:
		a1 = a
		a2 = a
		while True:
			x = (a1 - d) / 2
			if int(x) == x and x >= 0:
				res = abs(a1 - num)
				break
			else:
				a1 = a1 + 1
			x = (a2 - d) / 2
			if int(x) == x and x >= 0:
				res = abs(num - a2)
				break
			else:
				a2 = a2 - 1
	print(res)
	t = t - 1


import sys, math
import io, os

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

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
from decimal import Decimal
INF = float('inf')
mod = int(1000000000.0) + 7
for t in range(int(data())):
	(n, k) = mdata()
	if k >= n:
		out(k - n)
	elif (n + k) % 2 == 0:
		out(0)
	else:
		out(1)


from collections import *
from functools import *
import math
import sys
inp = sys.stdin.readline
out = sys.stdout.write

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

def li():
	return list(mi())

def ii():
	return int(inp())

def main():
	for _ in range(ii()):
		(n, k) = mi()
		if n == k:
			print(0)
		elif n > k:
			if n % 2 == 0 and k % 2 == 1 or (n % 2 == 1 and k % 2 == 0):
				print(1)
			else:
				print(0)
		else:
			print(k - n)
main()


T = int(input())
for _ in range(T):
	(n, k) = [int(x) for x in input().split(' ')]
	if n <= k:
		print(k - n)
	else:
		cond1 = k % 2
		cond2 = n % 2
		if cond1 and (not cond2):
			print(1)
		elif not cond1 and cond2:
			print(1)
		else:
			print(0)


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

def list_input():
	return list(map(int, input().split()))
for _ in range(int(input())):
	(n, k) = multiple_input()
	if k <= n:
		if k % 2 == n % 2:
			print(0)
		else:
			print(1)
	else:
		print(k - n)


T = int(input())
for t in range(1, T + 1):
	(n, k) = [int(inp) for inp in input().split()]
	if n < k:
		ans = k - n
	else:
		ans = (n - k) % 2
	print(str(ans))


from collections import deque
from sys import stdin
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(t,) = gil()
for _ in range(t):
	(n, k) = gil()
	if k >= n:
		print(k - n)
	else:
		print(n & 1 ^ k & 1)


t = int(input())
output = []
for i in range(t):
	list1 = input().split()
	n = int(list1[0])
	k = int(list1[1])
	if k >= n:
		answer = k - n
	elif (k + n) % 2 == 0:
		answer = 0
	else:
		answer = 1
	output.append(answer)
for item in output:
	print(item)


def read():
	return [int(x) for x in input().split()]
(cas,) = read()
for _ in range(cas):
	(n, k) = read()
	print(k - n if n < k else (n - k) % 2)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n < k:
		print(k - n)
	else:
		print(abs(k - n) % 2)


def getsol(n, k):
	if n < k:
		return k - n
	if n % 2 == k % 2:
		return 0
	return 1
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(getsol(n, k))


import sys, os, io

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

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

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

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

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

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions
from collections import deque, defaultdict, OrderedDict
from fractions import Fraction
from decimal import Decimal

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		(n, k) = ria()
		if n <= k:
			print(abs(k - n))
		elif n % 2 == k % 2:
			print(0)
		else:
			print(1)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

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

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

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

class FastWriter(io.IOBase):

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

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

class FastStdin(io.IOBase):

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

class FastStdout(io.IOBase):

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


from collections import Counter
import sys
for i in range(int(input())):
	(n, k) = map(int, input().split())
	if k == 0:
		if n % 2 == 0:
			print(0)
		else:
			print(1)
		continue
	if k > n:
		print(k - n)
	else:
		print((n - k) % 2)


def dist(n, k):
	if k == n:
		return 0
	elif k > n:
		return k - n
	elif n % 2 == k % 2:
		return 0
	else:
		return 1
t = int(input())
a = []
for i in range(t):
	(n, k) = list(map(int, input().split(' ')))
	a.append([n, k])
for x in a:
	print(dist(*x))


input = __import__('sys').stdin.readline
for _ in range(int(input())):
	(a, k) = map(int, input().split())
	ans = 0
	if a < k:
		ans += k - a
		a += k - a
	if (k + a) % 2:
		ans += 1
	print(ans)


n = int(input())
for i in range(n):
	xy = list(map(str, input().split()))
	x = int(xy[0])
	y = int(xy[1])
	if x < y:
		print(abs(y - x))
	elif x > y:
		if x % 2 == 0 and y % 2 == 0:
			print('0')
		elif x % 2 != 0 and y % 2 != 0:
			print('0')
		elif x % 2 == 0 and y % 2 != 0:
			print('1')
		else:
			print('1')
	else:
		print('0')


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10 ** 8)
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)
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')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 51, func=lambda a, b: a & b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

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

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for ik in range(int(input())):
	(n, k) = map(int, input().split())
	if n - k > 0:
		print((n - k) % 2)
	else:
		print(abs(n - k))


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, K):
	if N >= K:
		if (N - K) % 2 == 0:
			best = 0
		else:
			best = 1
	else:
		best = K - N
	return best
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N, K) = [int(x) for x in input().split()]
	ans = solve(N, K)
	print(ans)


for i in range(int(input())):
	(x, y) = map(int, input().split())
	if x >= y:
		if y % 2 == 0:
			if x % 2 == 0:
				print(0)
			else:
				print(1)
		elif x % 2 == 0:
			print(1)
		else:
			print(0)
	else:
		print(y - x)


def calc(a, k):
	if k >= a:
		return k - a
	elif a - k == 1 or a % 2 != k % 2:
		return 1
	return 0
t = int(input())
for zz in range(t):
	n = input().split()
	a = int(n[0])
	k = int(n[1])
	print(calc(a, k))


import sys
input = sys.stdin.readline
n = int(input())
for i in range(n):
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	print(max(k - n, (k - n) % 2))


from collections import Counter, defaultdict, deque
import sys
input = sys.stdin.readline

def solve():
	(a, k) = [int(x) for x in input().split()]
	if k >= a:
		print(k - a)
		return
	if (a - k) % 2:
		print(1)
	else:
		print(0)
tt = int(input())
for test in range(tt):
	solve()


import io, os
from collections import deque
import bisect
RL = lambda : list(map(int, input().split(' ')))
T = int(input())
for _ in range(T):
	(n, k) = RL()
	if k > n:
		print(k - n)
	elif (n + k) % 2:
		print(1)
	else:
		print(0)


def f():
	t = int(input())
	while t != 0:
		t -= 1
		L = [int(i) for i in input().split()]
		(A, K) = (L[0], L[1])
		if K > A:
			print(K - A)
		elif A % 2 == 0 and K % 2 == 0:
			print(0)
		elif A % 2 != 0 and K % 2 != 0:
			print(0)
		else:
			print(1)
f()


import math

def main():
	(n, k) = list(map(int, input().split()))
	if k % 2 == n % 2:
		print(max(0, k - n))
	else:
		print(max(1, k - n))

def __starting_point():
	t = int(input())
	for i in range(t):
		main()
__starting_point()


import sys
readline = sys.stdin.buffer.readline

def i1():
	return int(readline())

def mll(n):
	return ([int(s) for s in readline().split()] for i in range(n))

def redir(s):
	global readline
	import os
	fn = sys.argv[0] + f'/../in-{s}.txt'
	readline = open(fn).readline if os.path.exists(fn) else readline
redir('a')
t = i1()
for (n, k) in mll(t):
	print((n - k) % 2 if k < n else k - n)


a = int(input())
for i in range(a):
	(n, k) = list(map(lambda x: int(x), input().split()))
	if n == k:
		print(0)
		continue
	if k == 0:
		if n % 2 == 0:
			print(0)
			continue
		else:
			print(1)
			continue
	elif k > n:
		print(k - n)
		continue
	elif k % 2 == 0 and n % 2 == 0:
		print(0)
		continue
	elif k % 2 != 0 and n % 2 != 0:
		print(0)
		continue
	else:
		print(1)
		continue


from sys import stdin, stdout
from collections import defaultdict
import math
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(k - n)
	elif n % 2 == 0 and k % 2 != 0 or (n % 2 != 0 and k % 2 == 0):
		print(1)
	else:
		print(0)


import math
for _ in range(int(input())):
	(a, d) = map(int, input().split())
	if d == a:
		print(0)
	elif d < a:
		x = (a - d) / 2
		if math.ceil(x) == x:
			print(0)
		else:
			print(1)
	else:
		print(d - a)


def calc(n, k):
	return abs(n - k) if n < k else (n - k) % 2

def get_ints():
	return [int(n) for n in input().split()]

def get_floats():
	return [float(n) for n in input().split()]

def seq2str(seq):
	return ' '.join((str(item) for item in seq))
a = get_ints()
assert len(a) == 1
t = a[0]
for i in range(t):
	a = get_ints()
	assert len(a) == 2
	(n, k) = (a[0], a[1])
	res = calc(n, k)
	print(res)


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(n, k) = [int(c) for c in input().split()]
	if k > n:
		print(k - n)
	elif k == n:
		print(0)
	elif (n + k) % 2 == 0:
		print(0)
	else:
		print(1)


for _ in range(int(input())):
	ans = 0
	(n, k) = map(int, input().split())
	if n < k:
		ans = k - n
	elif n + k & 1:
		ans = 1
	print(ans)


t = int(input())
mn = 1
while mn <= t:
	inp = input().split(' ')
	(n, k) = (int(inp[0]), int(inp[1]))
	if n < k:
		print(k - n)
	elif (k + n) % 2 == 0:
		print(0)
	else:
		print(1)
	mn += 1


from collections import *
import sys
mod = 10 ** 9 + 7

def main():
	(n, k) = list(map(int, input().split()))
	if k >= n:
		print(k - n)
	elif k % 2 == 0:
		if n % 2 == 1:
			print(1)
		else:
			print(0)
	elif n % 2 == 0:
		print(1)
	else:
		print(0)
for i in range(int(input())):
	main()


t = int(input())

def ok(m, n, k):
	if abs(m - (n - m)) <= k:
		return True
	else:
		return False
for i in range(t):
	(n, k) = map(int, input().split())
	if n <= k:
		print(k - n)
	else:
		s = 0
		while True:
			l = 0
			r = n
			while r - l > 1:
				m = (r + l) // 2
				if ok(m, n, k):
					l = m
				else:
					r = m
			if abs(l - (n - l)) == k:
				print(s)
				break
			else:
				s += 1
				n += 1


t = int(input())
for case in range(t):
	(n, k) = list(map(int, input().split()))
	if k <= n:
		if k % 2 == n % 2:
			print(0)
		else:
			print(1)
	else:
		print(abs(n - k))


def solution(n, k):
	if n < k:
		return k - n
	return abs(n - k) % 2
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(solution(n, k))


import math
from decimal import *

def pf(n):
	ans = [1]
	if n % 2 == 0:
		if n != 2:
			ans.append(2)
		while n % 2 == 0:
			n //= 2
	p = 3
	while n > 1:
		if n % p == 0:
			ans.append(p)
			while n % p == 0:
				n //= p
		p += 1
	return ans
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(k - n)
	elif k == 0:
		print(n % 2)
	elif n % 2 != k % 2:
		print(1)
	else:
		print(0)


from sys import stdin, stdout
import math
input = stdin.readline
print = stdout.write
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	ans1 = abs(n - k)
	ans2 = math.inf
	if k < n:
		ans2 = (n - k) % 2
	print(str(min(ans1, ans2)) + '\n')


from sys import stdin, stdout, setrecursionlimit
from math import gcd, ceil, sqrt
from collections import Counter, deque
from bisect import bisect_left, bisect_right
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
setrecursionlimit(100000)
mod = 1000000007
tc = ii1()
for _ in range(tc):
	(n, k) = iia()
	if n == k:
		print(0)
	elif k > n:
		print(k - n)
	elif (n + k) % 2 == 0:
		print(0)
	else:
		print(1)


def main():
	t = int(input())
	nk = [[int(x) for x in input().split()] for i in range(t)]
	for i in nk:
		if i[0] < i[1]:
			print(i[1] - i[0])
			continue
		elif i[0] >= i[1]:
			if i[0] % 2 == 0 and i[1] % 2 == 0:
				print(0)
				continue
			if i[0] % 2 != 0 and i[1] % 2 != 0:
				print(0)
				continue
			else:
				print(1)
main()


for ctr in range(int(input())):
	(n, k) = map(int, input().split())
	d = k - n
	if d < 0:
		if n % 2 == k % 2:
			print(0)
		else:
			print(1)
	else:
		print(abs(n - k))


_ = int(input())
while _:
	(n, k) = list(map(int, input().split()))
	if k >= n:
		print(k - n)
	elif k % 2 == n % 2:
		print(0)
	else:
		print(1)
	_ -= 1


import sys
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(buff_readline())

def read_int_n():
	return list(map(int, buff_readline().split()))

def read_float():
	return float(buff_readline())

def read_float_n():
	return list(map(float, buff_readline().split()))

def read_str():
	return readline().strip()

def read_str_n():
	return readline().strip().split()

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

def slv(N, K):
	if N >= K:
		if N % 2 == K % 2:
			return 0
		else:
			return min(abs(N - K), 1)
	return abs(N - K)

def main():
	for _ in range(read_int()):
		(N, K) = read_int_n()
		print(slv(N, K))
main()


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
sys.setrecursionlimit(10 ** 6)
I = sys.stdin.readline

def ii():
	return int(I().strip())

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

def mi():
	return map(int, I().strip().split())

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

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

def main():
	ans = ''
	for _ in range(int(ii())):
		(n, k) = mi()
		if n == k:
			ans += '0\n'
		elif k == 0:
			if n % 2 == 0:
				ans += '0\n'
			else:
				ans += '1\n'
		elif n < k:
			ans += str(k - n) + '\n'
		elif n & 1 == k & 1:
			ans += '0\n'
		else:
			ans += '1\n'
	print(ans)
main()


def distance(n, k):
	if n < k:
		print(k - n)
	else:
		print((n - k) % 2)
t = int(input())
l1 = []
l2 = []
for i in range(t):
	(n, k) = map(int, input().split())
	l1.append(n)
	l2.append(k)
for i in range(len(l1)):
	distance(l1[i], l2[i])


for testcases in range(int(input())):
	(a, k) = map(int, input().split())
	if k > a:
		print(k - a)
	elif k == a:
		print(0)
	else:
		flag = -1
		flags = -1
		if a & 1 == 0:
			flag = 1
		if k & 1 == 0:
			flags = 1
		if flags * flag > 0:
			print(0)
		else:
			print(1)


import math
import sys
import itertools
import fractions
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
t = int(wtf[0])
for s in wtf[1:]:
	(n, k) = map(int, s.split())
	ans = 0
	if n < k:
		ans = k - n
	elif n % 2 == k % 2:
		ans = 0
	else:
		ans = 1
	print(ans)


for s in list(open(0))[1:]:
	(n, k) = map(int, s.split())
	print(k - n if n <= k else n - k & 1)


number = int(input())
list1 = []
for number in range(number):
	list1.append(str(input()))
for string in list1:
	data = string.split()
	n = int(data[0])
	k = int(data[1])
	if n < k or n == k:
		print(k - n)
	else:
		print((n - k) % 2)


import math
for _ in range(int(input())):
	(A, k) = map(int, input().split())
	if A > k:
		if (A + k) % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		print(abs(k - A))


import math
t = int(input())
out = []
for i in range(t):
	(n, k) = map(int, input().split())
	x = (n - k) / 2
	if x < 0:
		z = int(-2 * x)
		out.append(z)
	elif x > 0:
		if x == math.ceil(x):
			out.append(0)
		else:
			out.append(1)
	else:
		out.append(0)
for i in out:
	print(i)


t = int(input())
for i in range(t):
	(a, d) = map(int, input().split())
	if a > d:
		if (a - d) % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		print(d - a)


t = int(input())
for i in range(t):
	a = input()
	h = list(map(int, a.split(' ')))
	n = h[0]
	k = h[1]
	if k > n:
		print(k - n)
	else:
		print((n - k) % 2)


import sys

def solution():
	x = int(input())
	for i in range(x):
		line = input().split()
		(a, b) = (int(line[0]), int(line[1]))
		if b > a:
			print(b - a)
		elif a % 2 == b % 2:
			print(0)
		else:
			print(1)
solution()


def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
n = inp()
for _ in range(n):
	l = inlt()
	a = l[0]
	d = l[1]
	if a >= d:
		if (a - d) % 2:
			print(1)
		else:
			print(0)
	else:
		print(d - a)


t = int(input())

def checkio(n, k):
	if k > n:
		return k - n
	elif (k - n) % 2 == 0:
		return 0
	else:
		return 1
for i in range(t):
	(n, k) = list(map(int, input().split(' ')))
	print(checkio(n, k))


t = int(input())
for i in range(t):
	(n, k2) = map(int, input().split())
	if k2 >= n:
		print(k2 - n)
	elif n % 2 == k2 % 2:
		print(0)
	else:
		print(1)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ans = 0
	if n <= m:
		ans = m - n
	else:
		x = n - m
		if x % 2 == 0:
			ans = 0
		else:
			ans = 1
	print(ans)


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

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

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

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True
for _ in range(ii()):
	(n, k) = mi()
	if k >= n:
		print(k - n)
	elif abs(n - k) & 1:
		print(1)
	else:
		print(0)


from sys import stdin, stdout
inp = stdin.readline

def main():
	t = int(inp().strip())
	for i in range(t):
		(n, k) = map(int, inp().strip().split())
		stdout.write(str(k - n if k >= n else 1 if (k + n) % 2 else 0) + '\n')
main()


def min_steps(n, k):
	if n == k:
		return 0
	if n and k == 0:
		if n % 2:
			return 1
		if not n % 2:
			return 0
	if k and n == 0:
		return k
	if k > n:
		return k - n
	if k < n:
		if n % 2:
			if k % 2:
				return 0
			else:
				return 1
		elif k % 2:
			return 1
		else:
			return 0
t = int(input())
for _ in range(t):
	nk = input().split()
	n = int(nk[0])
	k = int(nk[1])
	print(min_steps(n, k))


def sol(x, y):
	if y >= x:
		print(y - x)
		return
	if y == 0:
		if x % 2:
			print(1)
			return
		print(0)
		return
	if y < x:
		if x % 2:
			if y % 2:
				print(0)
			else:
				print(1)
		elif y % 2:
			print(1)
		else:
			print(0)
k = int(input())
for i in range(k):
	lis = list(map(int, input().split(' ')))
	sol(lis[0], lis[1])


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	res = abs(a - b)
	if a % 2 == 0:
		if b % 2 == 0:
			if b <= a:
				print(0)
				continue
			d = b
			print(abs(a - d))
			continue
		else:
			a += 1
			if b <= a:
				print(1)
				continue
			print(abs(a - b) + 1)
	elif b % 2 == 1:
		if b <= a:
			print(0)
			continue
		d = b
		print(abs(a - d))
		continue
	else:
		a += 1
		if b <= a:
			print(1)
			continue
		print(abs(a - b) + 1)


import sys
input = sys.stdin.readline
MOD = 1000000007
MOD2 = 998244353
ii = lambda : int(input().strip('\n'))
si = lambda : input().strip('\n')
dgl = lambda : list(map(int, input().strip('\n')))
f = lambda : map(int, input().strip('\n').split())
il = lambda : list(map(int, input().strip('\n').split()))
ls = lambda : list(input().strip('\n'))
lsc = lambda : list(input().strip('\n').split(' '))
lsi = lambda : [int(i) for i in ls()]
let = 'abcdefghijklmnopqrstuvwxyz'
for _ in range(ii()):
	(n, k) = f()
	x = n - k
	if x < 0:
		print(-x)
	elif x % 2:
		print(1)
	else:
		print(0)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	n1 = n
	total_pos = 0
	if n - k < 0:
		total_pos += abs(n - k)
		n = k
	xb_pos = (n - k) / 2
	xb_neg = (n + k) / 2
	if n >= 2 * xb_pos:
		if abs(n - k) % 2:
			print(total_pos + 1)
		else:
			print(total_pos)
	elif abs(n1 + k) % 2:
		print(1)
	else:
		print(0)


for _ in range(int(input())):
	(end, diff) = map(int, input().split())
	if diff == 0:
		if end % 2 == 0:
			print(0)
		else:
			print(1)
	elif diff > end:
		print(diff - end)
	elif diff < end:
		if (end - diff) % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		print(0)


from sys import stdin, stdout
from collections import Counter, deque
from queue import PriorityQueue
helperConstants = True
helperUtilityFunctions = True

def input():
	return stdin.readline().strip()
if helperConstants:
	YES = 'YES'
	NO = 'NO'
	yes = 'yes'
	no = 'no'
	true = 'true'
	false = 'false'
	FALSE = 'FALSE'
	TRUE = 'TRUE'
	IMPOSSIBLE = 'IMPOSSIBLE'
	POSSIBLE = 'POSSIBLE'
if helperUtilityFunctions:

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

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

	def getInputIntegerMatrix(n):
		matrix = []
		for i in range(n):
			matrix.append(list(map(int, input().split())))
		return matrix

	def getInputStringMatrix(n):
		matrix = []
		for i in range(n):
			matrix.append(input())
		return matrix

	def outputIntegerMatrix(matrix):
		for i in range(len(matrix)):
			print(*matrix[i])

	def outputStringMatrix(matrix):
		for i in range(len(matrix)):
			print(matrix[i])

	def kickstartoutput(testcase, *outputs):
		print('Case #%d:' % testcase, *outputs)

def solve(t):
	(n, k) = getIntegerInputs()
	if n < k:
		print(k - n)
	elif n % 2 == k % 2:
		print(0)
	else:
		print(1)
for t in range(int(input())):
	solve(t + 1)


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	(a, k) = list(map(int, stdin.readline().split()))
	start = k
	if a < k:
		print(k - a)
	elif k & 1:
		if a & 1:
			print(0)
		else:
			print(1)
	elif a & 1:
		print(1)
	else:
		print(0)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	m = (n - k) // 2
	m2 = (n - k) / 2
	if m >= 0 and m == m2:
		print(0)
	elif m >= 0 and m != m2:
		print(1)
	else:
		print(abs(n - k))


Ans = []
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if k < n:
		x = (n + k) % 2
	else:
		x = k - n
	Ans.append(x)
for i in Ans:
	print(i)


import sys
input = sys.stdin.readline
for f in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(k - n)
	else:
		x = k - n
		if x % 2 == 0:
			print(0)
		else:
			print(1)


def equal(a, b):
	if a == 0:
		return b
	elif a == b:
		return 0
	elif b > a:
		return b - a
	return 0 if (a - b) % 2 == 0 else 1
t = int(input())
while t:
	(a, b) = [int(x) for x in input().split()]
	print(equal(a, b))
	t -= 1


from collections import Counter, deque
import math
from random import randint
from bisect import bisect
import sys
import re
import copy
MOD = 1000000007
MAX = sys.maxsize
MIN = -sys.maxsize

class get:

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

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

	def float():
		return list(map(float, input().split()))

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

def sqrt(x):
	return int(math.sqrt(x)) + 1

def gcd(*args):
	result = args[0]
	for item in args:
		result = math.gcd(result, item)
	return result

def LCM(a, b):
	return a * b // math.gcd(a, b)

def solve():
	(n, k) = get.map()
	if k >= n:
		print(k - n)
		return
	if n % 2 == 0 and k % 2 == 0:
		print(0)
		return
	if n % 2 == 1 and k % 2 == 1:
		print(0)
		return
	print(1)
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	(noe, koe) = (bool(n % 2), bool(k % 2))
	if k <= n:
		if noe and koe or (not koe and (not noe)):
			print(0)
		else:
			print(1)
	else:
		print(abs(n - k))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())

	def soln():
		if n + k <= 2 * n:
			if (n + k) % 2 == 0:
				return 0
			elif n + k + 1 <= 2 * n:
				return 1
		return abs(k - n)
	result = soln()
	print(result)


import sys
readline = sys.stdin.buffer.readline

def even(n):
	return 1 if n % 2 == 0 else 0
query = int(readline())

def func(a, k):
	if k <= a:
		if even(k) == even(a):
			print(0)
		else:
			print(1)
	else:
		print(k - a)
for _ in range(query):
	(n, k) = map(int, readline().split())
	func(n, k)


t = int(input())
while t > 0:
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	ans = 0
	if n < k:
		ans = k - n
	elif (n + k) % 2 == 0:
		ans = 0
	else:
		ans = 1
	print(ans)
	t -= 1


for x in range(int(input())):
	(p, q) = map(int, input().split())
	if q > p:
		print(q - p)
	else:
		print((p - q) % 2)


import math
t = int(input())
while t > 0:
	(oa, k) = map(int, input().split())
	if k > oa:
		print(abs(k - oa))
	elif (k + oa) % 2 == 0:
		print(0)
	else:
		print(1)
	t -= 1


for u in range(int(input())):
	y = [int(w) for w in input().split()]
	a = y[0]
	k = y[1]
	if k == 0 and a == 1:
		print(1)
	elif a <= k:
		print(k - a)
	elif (k + a) % 2 == 0:
		print(0)
	else:
		print(1)


t = int(input())
ans = []
for _ in range(t):
	[n, k] = list(map(int, input().split()))
	if n < k:
		ans.append(k - n)
	else:
		ans.append(n % 2 ^ k % 2)
for x in ans:
	print(x)


def solution(n, k):
	if n <= k:
		return k - n
	elif k % 2 == n % 2:
		return 0
	else:
		return 1
num_cases = int(input())
for _ in range(num_cases):
	(n, k) = map(int, input().split())
	print(solution(n, k))


t = int(input())
for i in range(t):
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	diff = abs(n - k)
	if k > n:
		ans = diff
	elif diff % 2 == 0:
		ans = 0
	else:
		ans = 1
	print(ans)


a = input()
for x in range(int(a)):
	c = input().split(' ')
	tag = int(c[0])
	tag1 = int(c[1])
	if tag1 == tag:
		print(0)
	elif tag1 > tag:
		print(tag1 - tag)
	elif (tag - tag1) % 2 == 0:
		print(0)
	else:
		print(1)


for l in [*open(0)][1:]:
	(N, K) = map(int, l.split())
	print(max(K - N, K + N & 1))


for t in range(int(input())):
	a = input().split()
	(n, k) = (int(a[0]), int(a[1]))
	if n <= k:
		print(k - n)
	elif n % 2 == k % 2:
		print(0)
	else:
		print(1)


def solve(o, a, k):
	if a == k:
		return 0
	elif k > a:
		return k - a
	if a % 2 == 0 and k % 2 == 0:
		return 0
	elif a % 2 == 0 and k % 2 != 0:
		return 1
	elif a % 2 != 0 and k % 2 == 0:
		return 1
	elif a % 2 != 0 and k % 2 != 0:
		return 0
for _ in range(int(input())):
	(a, k) = list(map(int, input().split()))
	o = 0
	print(solve(o, a, k))


tests = int(input())
for i in range(tests):
	(a, b) = list(map(int, input().split()))
	if b > a:
		print(b - a)
	elif (a - b) % 2 == 1:
		print('1')
	else:
		print('0')


for t in range(int(input())):
	(n, k) = map(int, input().split())
	ans = abs(n - k)
	if n > k:
		if (n + k) % 2 == 0:
			ans = 0
		else:
			ans = min(ans, 1)
	print(ans)


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq 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')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 998244353
EPS = 1e-06

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

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	(n, k) = value()
	ans = 0
	if n == k:
		ans = 0
	elif n < k:
		ans = k - n
	elif (n - k) % 2 == 0:
		ans = 0
	else:
		ans = 1
	print(ans)


t = int(input())
for i in range(t):
	(A, d) = [int(i) for i in input().split()]
	steps = 0
	if A < d:
		steps += d - A
		A = int(d)
	steps += (A - d) % 2
	print(steps)


for i in range(int(input())):
	(x, y) = map(int, input().split())
	if x >= y:
		print((x + y) % 2)
	else:
		print(abs(x - y))


import sys
from math import sqrt
from collections import OrderedDict
inpt = sys.stdin.readline

def inp():
	return int(inpt())

def inlist():
	return list(map(int, inpt().split()))

def instr():
	s = inpt()
	return list(s[:len(s) - 1])

def invr():
	return map(int, inpt().split())

class node(object):

	def __init__(self, x, p, h):
		(self.x, self.p, self.h) = (x, p, h)
		self.children = []

	def add_child(self, obj):
		self.children.append(obj)

def main():
	t = inp()
	for l in range(t):
		(n, k) = invr()
		if k >= n:
			print(k - n)
		elif n % 2 != k % 2:
			print(1)
		else:
			print(0)
main()


from __future__ import division, print_function
import os, sys
import math
import collections
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

class my_dictionary(dict):

	def __init__(self):
		self = dict()

	def add(self, key, value):
		self[key] = value

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

def si():
	return input()

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

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r))

def binary_search(arr, low, high, x):
	if high >= low:
		mid = (high + low) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binary_search(arr, low, mid - 1, x)
		else:
			return binary_search(arr, mid + 1, high, x)
	else:
		return -1

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

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

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

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def padded_bin_with_complement(x):
	if x < 0:
		return bin(2 ** 16 - abs(x))[2:].zfill(16)
	else:
		return bin(x)[2:].zfill(16)

def binaryToDecimal(binary):
	binary1 = binary
	(decimal, i, n) = (0, 0, 0)
	while binary != 0:
		dec = binary % 10
		decimal = decimal + dec * pow(2, i)
		binary = binary // 10
		i += 1
	print(decimal)

def CountFrequency(my_list):
	freq = {}
	for item in my_list:
		if item in freq:
			freq[item] += 1
		else:
			freq[item] = 1
	return freq

def pos(a):
	b = [0] * len(a)
	c = sorted(a)
	for i in range(len(a)):
		for j in range(len(a)):
			if c[j] == a[i]:
				b[i] = j
				break
	return b

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def commonn(a, b, n):
	c = []
	for i in range(n):
		if a[i] == b[i]:
			c.append('-1')
		else:
			c.append(b[i])
	return c

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

def sumdigit(n):
	n = str(n)
	k = 0
	for i in range(len(n)):
		k += int(n[i])
	return k

def main():
	for _ in range(ii()):
		(n, k) = mi()
		if k == 0:
			if n % 2:
				print(1)
			else:
				print(0)
		elif n == 0:
			print(k)
		elif k <= n:
			if abs(k - n) % 2 == 0:
				print(0)
			else:
				print(1)
		else:
			print(abs(k - 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')

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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
while t:
	t -= 1
	arr = list(map(int, input().split()))
	if arr[0] > arr[1]:
		if arr[0] % 2 == 0:
			if arr[1] % 2 == 0:
				print('0')
			else:
				print('1')
		elif arr[1] % 2 == 0:
			print('1')
		else:
			print('0')
	elif arr[0] < arr[1]:
		print(arr[1] - arr[0])
	else:
		print('0')


from math import *
t = int(input())
while t > 0:
	(a, d) = [int(i) for i in input().split()]
	if a == d:
		print(0)
	elif a < d:
		print(abs(d - a))
	elif a % 2 == 0 and d % 2 == 0 or (a % 2 != 0 and d % 2 != 0):
		print(0)
	else:
		print(1)
	t -= 1


import math
t = int(input())
for _ in range(0, t):
	(n, m) = map(int, input().split())
	if m > n:
		print(m - n)
	elif m % 2 == 0 and n % 2 == 0:
		print(0)
	elif m % 2 != 0 and n % 2 != 0:
		print(0)
	else:
		print(1)


import sys
li = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : sys.stdin.readline().strip().split()
ni = lambda : int(sys.stdin.readline().strip())
nsi = lambda : sys.stdin.readline().strip()
from collections import defaultdict as df
from math import *
t = ni()
for _ in range(t):
	(n, k) = map(int, input().split())
	if n <= k:
		print(k - n)
	elif n % 2 != 0 and k % 2 == 0:
		print(1)
	elif n % 2 == 0 and k % 2 != 0:
		print(1)
	else:
		print(0)


def main():
	(a, d) = [int(s) for s in input().split()]
	if a < d:
		return d - a
	if (a - d) % 2 == 0:
		return 0
	else:
		return 1
tests = int(input())
for _ in range(tests):
	print(main())


t = int(input())
for ii in range(t):
	(n, k) = map(int, input().split())
	if n < k:
		print(abs(n - k))
	else:
		div = (n + k) / 2
		if div == int((n + k) / 2):
			print(0)
		else:
			c = int((n + k) / 2)
			div = (n + k) / 2
			ans = 0
			while div != c:
				ans += 1
				n += 1
				c = int((n + k) / 2)
				div = (n + k) / 2
			print(ans)


num_cases = int(input())
output = []
for i in range(num_cases):
	(a_pos, diff) = map(int, input().split())
	if diff == 0:
		if a_pos % 2 == 0:
			output.append(0)
		else:
			output.append(1)
	elif a_pos == diff:
		output.append(0)
	elif a_pos == 0:
		output.append(diff)
	elif a_pos < diff:
		output.append(diff - a_pos)
	elif (a_pos - diff) % 2 == 0:
		output.append(0)
	else:
		output.append(1)
for i in range(num_cases):
	print(output[i])


import os
import sys
from io import BytesIO, IOBase
from collections import Counter, defaultdict
from collections import deque
from functools import cmp_to_key
import math

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

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

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007

def sieve(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
	s = set()
	for p in range(2, n + 1):
		if prime[p]:
			s.add(p)
	return s

def readTree(n, m):
	adj = [deque([]) for _ in range(n + 1)]
	for _ in range(m):
		(u, v) = ain()
		adj[u].append(v)
		adj[v].append(u)
	return adj

def main():
	for _ in range(iin()):
		(n, k) = ain()
		if k == 0:
			if n % 2 == 0:
				print(0)
			else:
				print(1)
		elif n == k:
			print(0)
		elif k > n:
			print(k - n)
		else:
			x1 = n + k
			x2 = n - k
			if x1 % 2 == 0 or x2 % 2 == 0:
				print(0)
			else:
				print(1)
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')
if os.getcwd() == 'D:\\code':
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n <= k:
		print(k - n)
	else:
		print((n - k) % 2)


num_test = int(input())
i = 1
output = []
while i <= num_test:
	i = i + 1
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	if k == 0:
		if n % 2 == 0:
			output.append(0)
		else:
			output.append(1)
		continue
	if n > k:
		if (n - k) % 2 == 0:
			output.append(0)
		else:
			output.append(1)
	else:
		output.append(k - n)
for item in output:
	print(item)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = 0
	if k > n:
		ans += k - n
		n += ans
	if n & 1 and k & 1 or (n & 1 == 0 and k & 1 == 0):
		print(ans)
	else:
		print(ans + 1)


for test in range(int(input())):
	(n, k) = map(int, input().split())
	ans = 0
	if n < k:
		ans += k - n
		n = k
	if (n + k) % 2 == 1:
		ans += 1
	print(ans)


import math
import os
import random
import re
import string
from sys import *
from collections import *

def bs(arr, x, l, r):
	if l <= r:
		mid = (r + l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return bs(arr, x, l, mid - 1)
		else:
			return bs(arr, x, mid + 1, r)
	else:
		return -1

def solve():
	for _ in range(int(input())):
		(n, k) = map(int, stdin.readline().strip().split())
		if k == n:
			print(0)
		elif k > n:
			print(abs(n - k))
		elif n % 2 == k % 2:
			print(0)
		else:
			print(1)
solve()


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

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

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass
for _ in range(L()[0]):
	(n, k) = L()
	if k == 0:
		print(n % 2)
		continue
	if n < k:
		print(k - n)
	else:
		print((n - k) % 2)
endtime = time.time()


for i in range(int(input())):
	(a, b) = map(int, input().split())
	if b >= a:
		print(abs(b - a))
	else:
		c = abs(a - b)
		if c % 2 == 0:
			print(0)
		else:
			print(1)


from functools import lru_cache
from sys import stdin, stdout
import sys
from math import *
input = stdin.readline
for __ in range(int(input())):
	(n, x) = map(int, input().split())
	if x % 2:
		if n >= x:
			if n % 2:
				print(0)
			else:
				print(1)
		else:
			print(x - n)
	elif n >= x:
		if n % 2:
			print(1)
		else:
			print(0)
	else:
		print(x - n)


nums = int(input())
N = []
for i in range(nums):
	N.append(input().split())
for num in N:
	k = int(num[1])
	n = int(num[0])
	if k <= n:
		if k % 2 == 0 and n % 2 == 0 or (k % 2 == 1 and n % 2 == 1):
			print(0)
		else:
			print(1)
	else:
		print(k - n)


import sys
t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	if k <= n:
		if n % 2 == k % 2:
			print(0)
		else:
			print(1)
	else:
		print(abs(n - k))


from math import *
for _ in range(int(input())):
	(a, k) = [int(x) for x in input().split()]
	if a >= k:
		if a % 2 == k % 2:
			print(0)
		else:
			print(1)
	else:
		print(abs(a - k))


def solve(n, k):
	if k == 0:
		return 1 if n % 2 else 0
	if n >= k:
		if k % 2 == 0:
			return 1 if n % 2 else 0
		else:
			return 1 if n % 2 == 0 else 0
	return k - n
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print(solve(n, k))


def steps(n, k):
	if k == n:
		return 0
	if k == 0:
		if n % 2 == 0:
			return 0
		else:
			return 1
	if k >= n:
		return k - n
	else:
		if n % 2 == 0 and k % 2 == 0:
			return 0
		if n % 2 != 0 and k % 2 != 0:
			return 0
		return 1
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(steps(n, k))


def resolve():
	loop_n = int(input())
	for _ in range(loop_n):
		(A, K) = map(int, input().split(' '))
		if K >= A:
			print(K - A)
		elif (K + A) % 2 == 0:
			print(0)
		else:
			print(1)
resolve()


T = int(input())
for _ in range(T):
	(a, k) = map(int, input().split())
	steps = 0
	if a < k:
		steps += k - a
		a = k
	if (a - k) % 2 == 1:
		steps += 1
	print(steps)


T = int(input())
for t in range(T):
	(A, k) = [int(j) for j in input().split()]
	if k > A:
		print(k - A)
	elif (A - k) % 2 == 0:
		print(0)
	else:
		print(1)


t = int(input())
l = []
for i in range(t):
	(n, m) = list(map(int, input().split()))
	l.append([n, m])
for j in l:
	if j[1] == 0:
		if j[0] % 2 == 0:
			print(0)
		else:
			print(1)
	elif j[1] >= j[0]:
		print(j[1] - j[0])
	elif j[0] > j[1]:
		if (j[0] - j[1]) % 2 == 0:
			print(0)
		else:
			print(1)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	ans = 10 ** 10
	ans = min(ans, abs(k - n))
	v1 = n % 2
	v2 = k % 2
	if n >= k:
		if v1 == v2:
			ans = 0
		else:
			ans = min(ans, 1)
	print(ans)


from sys import stdin
input = lambda : stdin.readline().strip()
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = 0
	if k >= n:
		ans = k - n
	elif (n + k) % 2 != 0:
		ans = 1
	else:
		ans = 0
	print(ans)


for y in range(int(input())):
	(a, k) = map(int, input().split())
	ans = 0
	if a > k:
		if (a + k) % 2 == 0:
			ans = 0
		else:
			ans = 1
	elif a == k:
		pass
	else:
		ans = k - a
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(k - n)
		continue
	else:
		p = 1
		c = 0
		while p:
			x = (n + k) / 2
			if int(x) - x == 0:
				print(c)
				break
			else:
				n = n - 1
				c += 1


res = []
for x in range(int(input())):
	(a, b) = map(int, input().split())
	c = 0
	if a <= b:
		c = b - a
		res.append(c)
	elif b == 0 and a % 2 != 0:
		c = 1
		res.append(c)
	elif b % 2 == 0 and a % 2 == 0:
		res.append(c)
	elif b % 2 != 0 and a % 2 != 0:
		res.append(c)
	elif a % 2 == 0 and b % 2 != 0:
		c = 1
		res.append(c)
	elif a % 2 != 0 and b % 2 == 0:
		c = 1
		res.append(c)
for y in res:
	print(y)


l = []
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if k <= n:
		if k % 2 == n % 2:
			l.append(0)
		else:
			l.append(1)
	else:
		l.append(abs(n - k))
for i in l:
	print(i)


import sys

def main():
	tn = int(input())
	for ti in range(tn):
		(n, k) = map(int, input().split())
		if n <= k:
			print(k - n)
		else:
			print((n - k) % 2)
main()


for nt in range(int(input())):
	(n, k) = map(int, input().split())
	if k < n:
		if n % 2 == 0:
			if k % 2:
				print(1)
			else:
				print(0)
			continue
		else:
			if k % 2:
				print(0)
			else:
				print(1)
			continue
	print(k - n)


def makeB(n, k):
	if n >= k:
		if n % 2 == k % 2:
			return 0
		else:
			return 1
	else:
		return k - n
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	print(makeB(n, k))


testcases = int(input())
set = []
for i in range(testcases):
	temp = input().split(' ')
	aval = int(temp[0])
	kval = int(temp[1])
	tup = (aval, kval)
	set.append(tup)

def minimizer(a, k):
	if a == k:
		return 0
	elif k < a and (a - k) % 2 == 0:
		return 0
	elif k < a and (a - k) % 2 == 1:
		return 1
	elif k > a:
		return k - a
for i in set:
	print(minimizer(i[0], i[1]))


from sys import stdin, stdout
ans = []

def main():
	(n, k) = list(map(int, stdin.readline().split()))
	if n < k:
		ans.append(str(k - n))
	elif int(n & 1) == int(k & 1):
		ans.append(str(0))
	else:
		ans.append(str(1))
for _ in range(int(stdin.readline())):
	main()
stdout.write('\n'.join(ans))


def inp_n():
	return int(input())

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

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

def is_odd(n):
	if n & 1:
		return True
	return False
for _ in range(inp_n()):
	(n, k) = inp_mul_num()
	if n > k:
		if n % 2 != 0 and k % 2 != 0 or (n % 2 == 0 and k % 2 == 0):
			print(0)
		else:
			print(1)
	elif n < k:
		print(k - n)
	else:
		print(0)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		print(k - n)
		continue
	p = n + k
	if p % 2 == 0:
		print(0)
	else:
		print(1)


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
t = int(input())
for tt in range(t):
	(n, k) = map(int, sys.stdin.readline().split(' '))
	x = n - k
	ans = 0
	if x < 0:
		ans += abs(x)
	elif x % 2 == 1:
		ans = 1
	print(ans)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


from sys import stdin, stdout

def main():
	t = int(stdin.readline())
	for i in range(t):
		(n, k) = [int(j) for j in stdin.readline().split()]
		if n < k:
			ans = k - n
		elif (n - k) % 2 == 0:
			ans = 0
		else:
			ans = 1
		stdout.write('{0}\n'.format(ans))
main()


import collections
import math

def write(arr, n):
	i = 0
	while n > 0:
		if n & 1 == 1:
			pass
		i += 1
		n = n >> 1
	print()
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n > k:
		if k % 2 != 0 and n % 2 == 0 or (k % 2 == 0 and n % 2 != 0):
			print(1)
		else:
			print(0)
	else:
		print(abs(k - n))


import sys
t = int(input())
for _ in range(t):
	(n, k) = map(int, sys.stdin.readline().strip().split())
	if k >= n:
		print(k - n)
	else:
		print(n & 1 ^ k & 1)


def main():
	for tt in range(int(input())):
		(n, k) = map(int, input().split())
		if n <= k:
			print(k - n)
		elif n > k:
			if n % 2 == k % 2:
				print(0)
			else:
				print(1)
main()


def parr(arr):
	print(*arr, sep=' ')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k <= n:
		print((n - k) % 2)
	else:
		print(k - n)


import math
t = int(input())
for q in range(t):
	(n, k) = [int(i) for i in input().split()]
	if n < k:
		print(k - n)
	elif (n - k) % 2 == 1:
		print(1)
	else:
		print(0)


import sys
inputlines = sys.stdin.readlines()
number_of_testcases = int(inputlines[0])
for i in range(number_of_testcases):
	(n, k) = list(map(int, inputlines[i + 1].split(' ')))
	if k >= n:
		print(k - n)
	elif (n - k) % 2 == 0:
		print(0)
	else:
		print(1)


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n < k:
		print(k - n)
	else:
		print((k - n) % 2)


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


from sys import stdin, stdout
from collections import Counter, OrderedDict
import math
cin = stdin.readline
cout = stdout.write
mp = lambda : list(map(int, cin().split()))

def chars():
	s = cin()
	return list(s[:len(s) - 1])

def pl(a):
	for val in a:
		cout(str(val) + ' ')
	cout('\n')
(t,) = mp()
for _ in range(t):
	(n, k) = mp()
	if k >= n:
		cout(str(k - n) + '\n')
	elif (n + k) % 2:
		cout('1\n')
	else:
		cout('0\n')


from sys import stdin, stdout
for query in range(int(stdin.readline())):
	nk = stdin.readline().split()
	n = int(nk[0])
	k = int(nk[1])
	if n > k:
		stdout.write(str((n - k) % 2) + '\n')
	else:
		stdout.write(str(k - n) + '\n')


def distance_and_axis(n: int, k: int) -> int:
	if k == 0 and n % 2 == 0:
		return 0
	elif k == 0:
		return 1
	elif n == 0:
		return k
	if k > n:
		return k - n
	b_prelim = (n - k) / 2
	if b_prelim.is_integer():
		return 0
	else:
		return 1
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split(' '))
	print(distance_and_axis(n, k))


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	(n, k) = map(int, stdin.readline().split())
	if k < n:
		if n % 2 == 0 and k % 2 == 0 or (n % 2 != 0 and k % 2 != 0):
			print(0)
		else:
			print(1)
	else:
		print(abs(n - k))


def allPermutations(string):
	listi = permutations(string)
	for i in list(listi):
		print(''.join(i))
from operator import add
t = int(input())
for _ in range(t):
	(a, k) = map(int, input().split())
	if k > a:
		print(k - a)
	elif k % 2 == a % 2:
		print(0)
	else:
		print(1)


from sys import stdin
input = lambda : stdin.readline().strip()
for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if a == b:
		print(0)
	elif a < b:
		print(b - a)
	else:
		c = (a - b) % 2
		if c == 0:
			print(0)
		else:
			print(1)


from sys import stdin

def main():
	input = lambda : stdin.readline()[:-1]
	T = int(input())
	for _ in [0] * T:
		(N, K) = map(int, input().split())
		a = N
		steps = []
		for b in ((a - K) // 2, (a - K) // 2 + K, a + K):
			k = b - abs(a - b)
			if k == K:
				print(0)
				break
			else:
				steps.append(abs(K - k))
		else:
			print(min(steps))
main()


for l in [*open(0)][1:]:
	(n, k) = map(int, l.split())
	print(max(k - n, k + n & 1))


for _ in ' ' * int(input()):
	(n, k) = map(int, input().split())
	if n >= k:
		if n % 2 == k % 2:
			print(0)
		else:
			print(1)
	else:
		print(abs(n - k))


def tInput():
	from sys import stdin
	input = stdin.readline
tInput()

def A():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		if n >= k:
			print(int(n % 2 != k % 2))
		else:
			print(k - n)
A()


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	(n, k) = map(int, input().split())
	if n <= k:
		print(k - n)
	elif n % 2 == k % 2:
		print(0)
	else:
		print(1)


from sys import *
from math import *
from sys import stdin, stdout
from collections import *
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)

def ans(n, k):
	if n < k:
		print(k - n)
	elif n == k:
		print(0)
	else:
		print((n - k) % 2)
for _ in range(int(input())):
	(n, k) = get_int()
	ans(n, k)


from sys import stdin, stdout
I = stdin.readline
for _ in range(int(I())):
	(n, k) = map(int, I().split())
	if k <= n:
		fla = n % 2
		flk = k % 2
		if fla == flk:
			print(0)
			continue
		else:
			print(1)
			continue
	else:
		print(k - n)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	if n == k:
		print(0)
	elif k > n:
		print(k - n)
	elif k == 0:
		if n % 2 == 0:
			print(0)
		else:
			print(1)
	elif (n - k) % 2 == 0:
		print(0)
	else:
		print(1)


for _t in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if k > n:
		print(k - n)
	elif k % 2 == n % 2:
		print(0)
	else:
		print(1)


import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

def solve(a, k):
	console('----- solving ------')
	if a <= k:
		console('check')
		return k - a
	return (k % 2 - a % 2) % 2

def console(*args):
	print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)
	return
for case_num in range(int(input())):
	(a, k) = list(map(int, input().split()))
	res = solve(a, k)
	print(res)


def main(n, k):
	if k == 0:
		if n % 2 == 0:
			return 0
		else:
			return 1
	elif n <= k:
		return abs(n - k)
	elif abs(k - n) % 2 == 0:
		return 0
	else:
		return 1
t = int(input())
for t_itr in range(t):
	nk = list(map(int, input().rstrip().split()))
	n = nk[0]
	k = nk[1]
	res = main(n, k)
	print(res)


T = int(input())
while T > 0:
	(n, k) = map(int, input().split())
	res = 0
	if n <= k:
		res = k - n
	elif n % 2 == 0:
		if k % 2 == 1:
			res = 1
	elif k % 2 == 0:
		res = 1
	print(res)
	T -= 1


import sys
pprint = lambda s: print(' '.join(map(lambda x: str(x), s)))
input = lambda : sys.stdin.readline().strip()
ipnut = input
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if (k - n) % 2 == 0:
		if k > n:
			print(k - n)
		else:
			print(0)
	elif k > n:
		print(k - n)
	else:
		print(1)


for j in range(int(input())):
	(a, b) = map(int, input().split())
	if b > a:
		print(b - a)
	elif a % 2 == 0:
		if a % 2 == 0 and b % 2 == 0:
			print(0)
		else:
			print(1)
	elif a % 2 != 0 and b % 2 != 0:
		print(0)
	else:
		print(1)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n < k:
		print(k - n)
	elif n == k or (k < n and n + k & 1 == 0):
		print(0)
	elif k < n and n + k & 1 == 1:
		print(1)


t = int(input())
res = []
for i in range(t):
	(n, k) = map(int, input().split())
	s = 0
	if k <= n:
		s = k + n
		if s % 2 == 0:
			res.append(0)
		else:
			res.append(1)
	else:
		res.append(k - n)
for i in res:
	print(i)


for case in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	if k >= n:
		print(k - n)
		continue
	if (n + k) % 2 == 0:
		print(0)
	else:
		print(1)


import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = 1
t = int(stdin.readline())
for _ in range(t):
	(n, k) = list(map(int, stdin.readline().rstrip().split()))
	if n <= k:
		print(k - n)
	elif (n - k) % 2 == 1:
		print(1)
	else:
		print(0)


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())
x = inp()
a = []
arv = 0
for i in range(x):
	(y, z) = invr()
	if y >= z:
		if (y + z) % 2 == 0:
			a.append(0)
		else:
			a.append(1)
	else:
		arv = abs(z - y)
		a.append(arv)
for i in a:
	print(i)


for t in range(int(input())):
	(aa, bb) = map(int, input().split())
	if aa == bb:
		print(0)
	elif bb > aa:
		print(bb - aa)
	elif bb % 2 == 0 and aa % 2 == 0 or (bb % 2 == 1 and aa % 2 == 1):
		print(0)
	else:
		print(1)


import sys

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

def input_split():
	return [int(i) for i in input().split()]
testCases = int(input())
answers = []
for _ in range(testCases):
	(n, k) = input_split()
	if k > n:
		ans = k - n
	elif (n + k) % 2 == 1:
		ans = 1
	else:
		ans = 0
	answers.append(ans)
print(*answers, sep='\n')


def test():
	t = int(input())
	while t > 0:
		t -= 1
		soln()

def soln():
	nk = list(map(int, input().split(' ')))
	n = nk[0]
	k = nk[1]
	if k >= n:
		print(k - n)
		return
	elif k % 2 == n % 2:
		print(0)
	else:
		print(1)
test()


from collections import Counter
from collections import OrderedDict
from collections import defaultdict
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n == k:
		print('0')
		continue
	elif k > n:
		print(k - n)
	elif n % 2 == k % 2:
		print('0')
	else:
		print('1')


try:
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		if k >= n:
			print(k - n)
		else:
			n = n - k
			if n % 2 == 0:
				print(0)
			else:
				print(1)
except:
	pass


from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
	(n, k) = map(int, stdin.readline().split())
	if n >= k and n % 2 == k % 2:
		print(0)
	elif n >= k:
		print(1)
	else:
		print(k - n)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	if n < m:
		print(m - n)
	elif n % 2 == m % 2:
		print(0)
	else:
		print(1)


import sys
entries = int(input())
for x in range(entries):
	line = input()
	line = line.strip()
	ints = line.split(' ')
	n = int(ints[0])
	k = int(ints[1])
	if k >= n:
		print(k - n)
	elif k % 2 != n % 2:
		print(1)
	else:
		print(0)


cases = int(input())
for z in range(cases):
	testCase = input().split(' ')
	testCase[0] = int(testCase[0])
	testCase[1] = int(testCase[1])
	if testCase[0] >= testCase[1] - 1:
		print((testCase[0] - testCase[1]) % 2)
	else:
		print(testCase[1] - testCase[0])


t = int(input())
for i in range(t):
	s = input().split(' ')
	n = int(s[0])
	k = int(s[1])
	a1 = abs(k - n)
	if n >= k:
		if (n - k) % 2 == 0:
			a1 = 0
		else:
			a1 = 1
	print(a1)


import sys

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

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

def Num():
	return int(input())
for _ in range(Num()):
	(n, k) = List()
	if k >= n:
		print(k - n)
	elif k == 0 and n / 2 - int(n / 2) == 0:
		print(0)
	elif n & 1 and (not k & 1):
		print(1)
	elif not n & 1 and k & 1:
		print(1)
	else:
		print(0)


t = int(input())
i = 0
while i < t:
	(n, k) = map(int, input().split())
	if k % 2 == 0:
		if n % 2 == 0:
			if k <= n:
				print('0')
			else:
				print(k - n)
		elif k < n:
			print('1')
		else:
			print(k - n)
	elif n % 2 == 0:
		if k < n:
			print('1')
		else:
			print(k - n)
	elif k <= n:
		print('0')
	else:
		print(k - n)
	i += 1


t = int(input())
while t > 0:
	t -= 1
	line = input().split(' ')
	a = int(line[0])
	k = int(line[1])
	if k == a:
		print(0)
		continue
	if k > a:
		print(abs(a - k))
		continue
	if k < a:
		if a % 2 == 1 and k % 2 == 1:
			print(0)
		if a % 2 == 1 and k % 2 == 0:
			print(1)
		if a % 2 == 0 and k % 2 == 0:
			print(0)
		if a % 2 == 0 and k % 2 == 1:
			print(1)


t = int(input())
a = []
for i in range(t):
	x = list(map(int, input().split()))
	n = x[0]
	k = x[1]
	if n <= k:
		r = k - n
	elif n % 2 == k % 2:
		r = 0
	elif n % 2 != k % 2:
		r = 1
	a.append(int(r))
for i in range(len(a)):
	print(a[i])


from math import gcd
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a <= b:
		print(b - a)
	elif a % 2 != 0 and b % 2 == 0:
		print(1)
	elif a % 2 == 0 and b % 2 != 0:
		print(1)
	else:
		print(0)


tc = int(input())

def B(A, K):
	tot = 0
	tot += max(0, K - A)
	A += tot
	if A & 1 == 1:
		if K & 1 == 0:
			tot += 1
	elif K & 1 == 1:
		tot += 1
	return tot
for i in range(tc):
	tc = input()
	(A, K) = tc.split()
	print(B(int(A), int(K)))


T = int(input())
for _ in range(T):
	(a, b) = map(int, input().split())
	ans = 0
	if b > a:
		ans = b - a
	elif (a + b) % 2 != 0:
		ans = 1
	print(ans)


k = int(input())
lis = []
for i in range(k):
	a = list(map(int, input().split()))
	if a[1] <= a[0]:
		if (a[1] + a[0]) % 2 == 0:
			lis.append('0')
		else:
			lis.append('1')
	else:
		lis.append(a[1] - a[0])
for i in lis:
	print(i)


def solve():
	(a, d) = map(int, input().split())
	if a < d:
		print(d - a)
	elif a % 2 == d % 2:
		print(0)
	else:
		print(1)
for __ in range(int(input())):
	solve()


t = int(input())
while t:
	(a, b) = map(int, input().split())
	if b > a:
		print(abs(a - b))
	elif a % 2 == 0 and b % 2 == 0:
		print(0)
	elif a % 2 != 0 and b % 2 != 0:
		print(0)
	else:
		print(1)
	t -= 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(abs(k - n))
	else:
		b = (n - k) / 2
		if b.is_integer():
			print('0')
		else:
			print('1')


tc = int(input())
for i in range(tc):
	(n, k) = map(int, input().split())
	if n < k:
		print(k - n)
	else:
		answer = 0 if n % 2 == k % 2 else 1
		print(answer)


def steps(n, k):
	if n == k:
		return 0
	elif n == 0:
		return k
	elif k > n:
		return k - n
	elif n > k:
		if n % 2 == k % 2 == 0:
			return 0
		elif n % 2 and k % 2 == 0:
			return 1
		elif n % 2 == 0 and k % 2:
			return 1
		else:
			return 0
t = int(input())
for _ in range(t):
	nk = list(map(int, input().strip().split()))
	result = steps(nk[0], nk[1])
	print(result)


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
t = int(input())
while t:
	(n, k) = map(int, input().split())
	if k > n:
		print(k - n)
	else:
		print((n - k) % 2)
	t -= 1


def solve(n, k):
	if n <= k:
		ans = k - n
	elif n % 2 == k % 2:
		ans = 0
	else:
		ans = 1
	return ans
t = int(input())
while t:
	(n, k) = map(int, input().split(' '))
	print(solve(n, k))
	t = t - 1


from math import *
from sys import *
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n == k:
		print(0)
	elif n > k:
		p = n % 2
		m = k % 2
		if p == m:
			print(0)
		else:
			print(1)
	else:
		print(k - n)


t = int(input())
for _ in range(t):
	n = list(map(int, input().split()))
	num = 0
	if n[0] < n[1]:
		num += n[1] - n[0]
		n[0] = n[1]
	if (n[0] - n[1]) % 2 != 0:
		num += 1
	print(num)


import math
T = int(input())
for i in range(T):
	(n, k) = map(int, input().split())
	if n > k and n % 2 != k % 2:
		print(1)
	else:
		print(max(0, k - n))


def solve(n, k):
	if k >= n:
		print(k - n)
	elif n % 2 == 0 and k % 2 == 0 or (n % 2 == 1 and k % 2 == 1):
		print(0)
	else:
		print(1)
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	solve(n, k)


n = int(input())
B = []
for i in range(n):
	A = list(map(int, input().split()))
	if A[0] == A[1]:
		B.append(0)
	elif A[1] == 0:
		B.append(0 if A[0] % 2 == 0 else 1)
	elif A[0] % 2 == 0 and A[1] % 2 == 0:
		B.append(0 if A[0] > A[1] else A[1] - A[0])
	elif A[0] % 2 != 0 and A[1] % 2 != 0:
		B.append(0 if A[0] > A[1] else A[1] - A[0])
	else:
		B.append(1 if A[0] > A[1] else A[1] - A[0])
for i in B:
	print(i)


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = int(z())
for _ in range(num):
	(a, b) = zz()
	n1 = (a + b) / 2
	n2 = (a - b) / 2
	t = ceil(n1)
	t1 = ceil(n2)
	print(abs(t) + abs(t1) - a)


for _ in range(int(input())):
	(A, difference) = [int(x) for x in input().split()]
	if A >= difference:
		if A % 2 == difference % 2:
			print(0)
		else:
			print(1)
	else:
		print(difference - A)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	res = max(0, k - n)
	n += res
	if (n ^ k) & 1:
		res += 1
	print(res)


import sys

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

def in1():
	return int(input())
for _ in range(in1()):
	(a, b) = get_line()
	if b >= a:
		print(b - a)
	elif a % 2 == 0 and b % 2 == 0 or (a % 2 != 0 and b % 2 != 0):
		print(0)
	else:
		print(1)


import sys
input = sys.stdin.readline

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

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

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0, hi=None):
	if hi == None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

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

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

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

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math

def solve():
	(n, k) = map(int, input().split())
	val = (k + n) / 2
	if val < n:
		if math.ceil(val) == math.floor(val):
			print(0)
		else:
			print(1)
	else:
		print(k - n)
for _ in range(int(input())):
	solve()


(T,) = map(int, input().split())
import sys
input = sys.stdin.readline
for _ in range(T):
	(a, b) = map(int, input().split())
	if a >= b:
		if 1 - (a - b) % 2:
			print(0)
		else:
			print(1)
	else:
		print(b - a)


import sys
input = sys.stdin.readline

def invr():
	return map(int, input().split())
testcases = input()
for _ in range(int(testcases)):
	temp = invr()
	(n, k) = temp
	res = 0
	if n % 2 != k % 2:
		res += 1
	if n > k:
		print(res)
	else:
		print(k - n)


import sys
from sys import stdin, stdout
import math
import time
from functools import lru_cache
from collections import Counter
import heapq
try:
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		ans = 0
		if k >= n:
			ans = k - n
		elif k % 2 == 0:
			if n % 2 == 1:
				ans = 1
		elif n % 2 == 0:
			ans = 1
		print(ans)
except EOFError as e:
	print(e)


def checker(n, k):
	return k - n if n < k else 0 if n % 2 == k % 2 else 1
for _ in range(int(input())):
	(N, K) = [int(i) for i in input().split()]
	print(checker(N, K))


n = int(input())
while n:
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a <= b:
		print(b - a)
	elif a % 2 == 1 and b % 2 == 0 or (a % 2 == 0 and b % 2 == 1):
		print('1')
	else:
		print('0')
	n -= 1


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print(max(k - n, n + k & 1))


t = int(input())
for x in range(t):
	nk = list(map(int, input().split()))
	(n, k) = (nk[0], nk[1])
	if n <= k:
		print(k - n)
	elif abs(n - k) % 2 == 0:
		print(0)
	else:
		print(1)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if k > n:
		print(max(0, k - n))
	else:
		print((n - k) % 2)


import sys, math
t = int(sys.stdin.readline())
for _ in range(t):
	(n, k) = map(int, sys.stdin.readline().split())
	x = n
	if n % 2 != k % 2:
		x += 1
	if x < k:
		x = k
	print(x - n)


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase
sys.setrecursionlimit(10 ** 5)

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

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		if n % 2 == 0 and k == 0:
			print(0)
		elif k >= n:
			print(k - n)
		elif (n + k) % 2 == 0:
			print(0)
		else:
			print(1)
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')
main()


for _ in range(int(input())):
	(a, k) = map(int, input().split())
	ans = 0
	if k <= a:
		if abs(k - a) % 2 == 0:
			ans = 0
		else:
			ans = 1
	else:
		ans = abs(a - k)
	print(ans)


import math

def read_ints():
	return map(int, input().split())
p = int(input())
for i in range(p):
	a = []
	a = list(read_ints())
	if a[0] > a[1]:
		if a[0] % 2 == 0:
			if a[1] % 2 == 0:
				print(0)
			else:
				print(1)
		if a[0] % 2 != 0:
			if a[1] % 2 == 0:
				print(1)
			else:
				print(0)
	else:
		print(a[1] - a[0])


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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class union_find:

	def __init__(self, n):
		self.n = n
		self.rank = [0] * n
		self.parent = [int(j) for j in range(n)]

	def union(self, i, j):
		i = self.find(i)
		j = self.find(j)
		if self.rank[i] == self.rank[j]:
			self.parent[i] = j
			self.rank[j] += 1
		elif self.rank[i] > self.rank[j]:
			self.parent[j] = i
		else:
			self.parent[i] = j

	def find(self, i):
		temp = i
		if self.parent[temp] != temp:
			self.parent[temp] = self.find(self.parent[temp])
		return self.parent[temp]
from math import log2, ceil
from collections import deque, Counter as CC

def main():
	for t in range(int(input())):
		(n, k) = [int(j) for j in input().split()]
		if n >= k:
			if n % 2 == k % 2:
				print(0)
			else:
				print(1)
		else:
			print(k - n)
main()


import sys, math, heapq, copy
from collections import defaultdict, deque
from bisect import bisect_left, bisect_right
from functools import cmp_to_key
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if k <= n:
		if k % 2 == n % 2:
			print(0)
		else:
			print(1)
	else:
		print(k - n)


for t in range(int(input())):
	c = 0
	data = [int(x) for x in input().split()]
	n = data[0]
	k = data[1]
	if n > k:
		if n - k > 1 and (n + k) % 2 == 0:
			ans = 0
		else:
			ans = 1
	else:
		ans = abs(n - k)
	print(ans)


def find_diff():
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	if n < k:
		print(k - n)
	else:
		print((n - k) % 2)
t = int(input())
s = 1
while s <= t:
	find_diff()
	s += 1


test = int(input())
for abc in range(test):
	(myNum, difference) = list(map(int, input().split()))
	if difference == 0:
		if myNum % 2 == 0:
			print(0)
		else:
			print(1)
	elif difference >= myNum:
		print(difference - myNum)
	elif myNum & 1 == 0 and difference & 1 == 0 or (myNum & 1 != 0 and difference & 1 != 0):
		print(0)
	else:
		print(1)


T = int(input())
while T != 0:
	(n, k) = map(int, input().strip().split())
	if k % 2 == 1:
		if n >= k:
			if n % 2 == 1:
				print(0)
			else:
				print(1)
		else:
			print(k - n)
	elif n >= k:
		if n % 2 == 1:
			print(1)
		else:
			print(0)
	else:
		print(k - n)
	T -= 1


for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	n1 = n
	if n > k:
		x = (n - k) // 2
		if x * 2 != n - k:
			ans = 1
		else:
			ans = 0
	else:
		ans = k - n
	print(ans)


def main():
	t = int(input())
	for case in range(t):
		(n, k) = [int(x) for x in input().split()]
		if k == 0:
			if n % 2 == 0:
				print(0)
			else:
				print(1)
			continue
		if n == k:
			print(0)
			continue
		if n < k:
			print(k - n)
			continue
		if n > k:
			if k % 2 == 0 and n % 2 == 0:
				print(0)
			elif k % 2 != 0 and n % 2 != 0:
				print(0)
			else:
				print(1)
			continue
	return
main()


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, k) = LI()
		if n <= k:
			r = k - n
		else:
			r = (n - k) % 2
		rr.append(r)
	return JA(rr, '\n')
print(main())


from sys import stdin
for _ in range(int(stdin.readline())):
	(n, k) = list(map(int, stdin.readline().split()))
	if k > n:
		print(k - n)
	elif n % 2 != k % 2:
		print(1)
	else:
		print(0)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	ans = abs(n - k)
	if n >= k:
		if n & 1 == k & 1:
			ans = 0
		else:
			ans = 1
	print(ans)


t = int(input())
while t:
	(N, K) = map(int, input().split())
	a = K - N
	b = K + N
	c = b & 1
	print(max(a, c))
	t -= 1


from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
from collections import Counter
from math import sqrt
import collections
import math
import heapq
import re

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def most_frequent(list):
	return max(set(list), key=list.count)

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

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def Convert(string):
	li = list(string.split(''))
	return li

def SieveOfEratosthenes(n):
	global prime
	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
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
prime = []
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def main():
	for _ in range(inin()):
		(n, k) = map(int, input().split())
		if k >= n:
			print(abs(k - n))
		elif n & 1 == 1:
			if k & 1 == 0:
				print(1)
			else:
				print(0)
		elif k & 1 == 0:
			print(0)
		else:
			print(1)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
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
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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()


for t in range(int(input())):
	(a, b) = map(int, input().split())
	if b >= a:
		print(b - a)
	elif b == 0:
		print(a % 2)
	else:
		print((b - a) % 2)


t = int(input())
for i in range(t):
	a = list(map(int, input().split()))
	r = a[1] - a[0]
	if r >= 0:
		print(r)
	else:
		abs(r)
		if r % 2 == 0:
			print(0)
		else:
			print(1)


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left
from bisect import bisect_right

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

def In():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())
P = 1000000007

def main():
	for t in range(I()):
		(n, k) = In()
		if k == 0:
			if n % 2 == 0:
				print(0)
			else:
				print(1)
		elif n <= k:
			print(abs(n - k))
		elif (n - k) % 2 == 0:
			print(0)
		else:
			print(1)
main()


def solve():
	(n, k) = [int(i) for i in input().split()]
	if n < k:
		print(k - n)
		return
	if n % 2 == 0:
		if k % 2 == 1:
			print(1)
		else:
			print(0)
	elif k % 2 == 0:
		print(1)
	else:
		print(0)
test = int(input())
while test:
	solve()
	test -= 1


from sys import stdin, stdout
import bisect
import math
from collections import deque
mod = 10 ** 9 + 7

def st():
	return list(stdin.readline().strip())

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

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

def mp():
	return map(int, stdin.readline().split())

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

def DFS(dictionary, vertex, visited):
	visited[vertex] = True
	stack = [vertex]
	print(vertex)
	while stack:
		a = stack.pop()
		for i in dictionary[a]:
			if not visited[i]:
				print(i)
				visited[i] = True
				stack.append(i)

def BFS(dictionary, vertex, visited):
	visited[vertex] = True
	q = deque()
	q.append(vertex)
	while q:
		a = q.popleft()
		for i in dictionary[a]:
			if not visited[i]:
				visited[i] = True
				q.append(i)
				print(i)

def soe(limit):
	l = [1] * (limit + 1)
	l[0] = 0
	l[1] = 0
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

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

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
		a *= a
		n = n >> 1
	return r

def solve():
	(n, k) = mp()
	if n == k:
		pr(0)
		return
	if n < k:
		pr(k - n)
		return
	if n % 2 == k % 2:
		pr(0)
		return
	else:
		pr(1)
		return
for _ in range(inp()):
	solve()


def solve(n, k):
	if k >= n:
		return abs(n - k)
	if n & 1 and k & 1:
		return 0
	if n & 1 == 0 and k & 1 == 0:
		return 0
	return 1
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print(solve(n, k))


t = int(input())
for i in range(t):
	(a, b) = input().split(' ')
	n = int(a)
	k = int(b)
	steps = 0
	s = n // 2
	t = n % 2
	t2 = k % 2
	if t == t2:
		if t == 1:
			k -= 1
		else:
			pass
	elif t == 1:
		steps += 1
		s += 1
	else:
		steps += 1
		k -= 1
	if 2 * s < k:
		steps += k - 2 * s
	print(steps)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if k == n:
		print(0)
		continue
	if k < n:
		if k & 1 == n & 1:
			print(0)
		else:
			print(1)
	else:
		print(abs(n - k))


from sys import *
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k > n:
		stdout.write(str(k - n) + '\n')
	elif n % 2 == 0:
		if k % 2 == 0:
			stdout.write('0\n')
		else:
			stdout.write('1\n')
	elif k % 2 == 0:
		stdout.write('1\n')
	else:
		stdout.write('0\n')


for _ in ' ' * int(input()):
	(n, k) = list(map(int, input().split()))
	print([k - n, (n - k) % 2][n > k])


t = int(input())
b = []
for i in range(t):
	h = list(map(int, input().split()))
	b.append(h)

def tully(b0, b1):
	ret = 0
	if b1 > b0:
		ret = b1 - b0
	elif b0 > b1:
		if b0 % 2 == 0 and b1 % 2 == 0 or (b1 % 2 != 0 and b0 % 2 != 0):
			ret = 0
		else:
			ret = 1
	elif b1 == b0:
		ret = 0
	return ret
for i in range(t):
	y = tully(b[i][0], b[i][1])
	print(y)


def func(n, k):
	print(0 + (n % 2 != k % 2)) if n >= k else print(abs(n - k))
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	func(n, k)


n = int(input())
while n > 0:
	n -= 1
	(l, m) = map(int, input().split())
	if l / 2 + m / 2 < l and (l / 2 + m / 2) % 1 == 0:
		print(0)
		continue
	elif l / 2 + m / 2 < l:
		print(1)
	else:
		print(abs(m - l))


def dis(n, k):
	if k >= n:
		return abs(k - n)
	else:
		m = (k + n) / 2
		if (k + n) % 2 == 0:
			return 0
		else:
			count = 0
			while (k + n) % 2 != 0:
				m = (k + n) / 2
				n += 1
				count += 1
			return count
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	print(dis(n, k))


from math import *
from collections import *
from random import *
from decimal import Decimal
from heapq import *
from bisect import *
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 5)

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

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

def inp():
	return int(input())

def st1():
	return input().rstrip('\n')
t = inp()
while t:
	t -= 1
	(n, k) = ma()
	if n > k:
		if n % 2 == k % 2:
			print(0)
		else:
			print(1)
	else:
		print(abs(n - k))


t = int(input())
for q in range(t):
	ch = input()
	L = [int(i) for i in ch.split()]
	(a, b) = (L[0], L[1])
	if a <= b:
		print(b - a)
	elif a % 2 == b % 2:
		print(0)
	else:
		print(1)


num = int(input())
for i in range(num):
	s = input()
	for i in range(len(s)):
		if s[i] == ' ':
			n = [s[0:i] for x in range(i)]
			k = [s[i + 1:len(s)] for x in range(i, len(s), len(s) - i)]
	n = n[0]
	k = k[0]
	n = int(n)
	k = int(k)
	if k > n:
		output = k - n
	elif k == n:
		output = 0
	elif k < n:
		if k % 2 == 0:
			if n % 2 == 0:
				output = 0
			else:
				output = 1
		if k % 2 != 0:
			if n % 2 == 0:
				output = 1
			else:
				output = 0
	print(output)


from sys import stdout, stdin
(_input, _print) = (stdin.readline, stdout.write)
(_range, _int) = (range, int)

def solution():
	for _ in _range(_int(_input())):
		(a, k) = [_int(i) for i in _input().split()]
		if a - k >= 0:
			if (a - k) % 2 == 0:
				print(0)
			else:
				print(1)
		else:
			print(k - a)
solution()


test = int(input())
for tes in range(test):
	(l, m) = list(map(int, input().split()))
	if m == 0:
		if l % 2 == 0:
			print(0)
		else:
			print(1)
	elif l <= m:
		print(m - l)
	elif l % 2 == 0 and m % 2 == 0:
		print(0)
	elif l % 2 != 0 and m % 2 != 0:
		print(0)
	else:
		print(1)


for t in range(int(input())):
	(a, k) = list(map(int, input().split()))
	if k > a:
		print(k - a)
	elif k == a:
		print(0)
	elif k % 2 == 0:
		if a % 2 == 0:
			print(0)
		else:
			print(1)
	elif a % 2 != 0:
		print(0)
	else:
		print(1)


t = int(input())
while t:
	t -= 1
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	if n == k:
		print(0)
		continue
	if n < k:
		print(k - n)
		continue
	print((k + n) % 2)


n = int(input())
d = []
p = -2
for i in range(1, n + 1):
	(a, b) = map(int, input().split())
	d.append(a)
	d.append(b)
for j in range(1, n + 1):
	t = 0
	p = p + 2
	c = d[p]
	h = d[p + 1]
	if h > c:
		g = h - c
		print(g)
	else:
		u = c + h
		e = c - h
		while u % 2 != 0 and e % 2 != 0:
			t = t + 1
			u = c + t + h
			e = c + t - h
		print(t)


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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
for _ in range(int(ri())):
	(n, k) = Ri()
	if k >= n:
		print(k - n)
	elif (k + n) % 2 == 0:
		print(0)
	else:
		print(1)


test_cases = int(input())
for _ in range(test_cases):
	(n, k) = [int(i) for i in input().split(' ')]
	if n <= k:
		print(k - n)
	else:
		print((n + k) % 2)


def solve():
	(n, k) = map(int, input().split())
	if k >= n:
		return k - n
	if n % 2 == 0 and k % 2 != 0:
		return 1
	if n % 2 != 0 and k % 2 == 0:
		return 1
	return 0
t = int(input())
while t != 0:
	res = solve()
	print(res)
	t -= 1


from sys import stdin, stdout
from math import ceil

def find(N, K):
	if K > N:
		return K - N
	return 2 * ceil((N - K) / 2) + K - N

def main():
	for _ in range(int(stdin.readline())):
		(N, K) = list(map(int, stdin.readline().split()))
		print(find(N, K))
main()


for w in range(int(input())):
	(n, k) = tuple(map(int, input().split()))
	if n == k:
		print(0)
	elif k == 0:
		if n % 2 == 0:
			print(0)
		else:
			print(1)
	elif n < k:
		print(abs(n - k))
	elif n % 2 == 0:
		if k % 2 != 0:
			print(1)
		else:
			print(0)
	elif k % 2 == 0:
		print(1)
	else:
		print(0)


for _ in range(int(input())):
	(n, k) = [int(c) for c in input().split()]
	if k >= n:
		print(k - n)
	elif n + k & 1:
		print(1)
	else:
		print(0)


t = int(input())
for you in range(t):
	l = input().split()
	n = int(l[0])
	k = int(l[1])
	if n == k:
		print(0)
		continue
	if k < n and k % 2 != n % 2:
		print(1)
		continue
	if k < n:
		print(0)
		continue
	print(k - n)


n = int(input())
for i in range(n):
	(a, k) = list(map(int, input().split()))
	nat = 0
	if a < k:
		nat += abs(a - k)
		a = k
	if (a - k) % 2 != 0:
		nat += 1
	print(nat)


t = int(input())
for _ in range(t):
	(n, k) = (int(i) for i in input().split())
	if n == k:
		print(0)
	elif n < k:
		print(k - n)
	else:
		print((n - k) % 2)


n = int(input())
while n > 0:
	(a, b) = map(int, input().split())
	if a > b:
		if (a - b) % 2 != 0:
			print('1')
		else:
			print('0')
	elif a <= b:
		print(b - a)
	n -= 1


import time, math as mt, bisect as bs, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IP():
	return map(int, stdin.readline().split())

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

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

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

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * (2 * 10 ** 5 + 5)
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(2 * 10 ** 5 + 5):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 7
spf = [mx] * (mx + 1)

def SPF():
	spf[1] = 1
	for i in range(2, mx + 1):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx + 1, i):
				if i < spf[j]:
					spf[j] = i
	return

def readTree(n, e):
	adj = [set() for i in range(n + 1)]
	for i in range(e):
		(u1, u2) = IP()
		adj[u1].add(u2)
	return adj
mod = 10 ** 9 + 7

def solve():
	(n, k) = IP()
	if k == 0 and n % 2 == 0:
		P(0)
		return
	if k == 0 and n % 2 != 0:
		P(1)
		return
	if k <= n:
		if k % 2 == 0 and n % 2 == 0:
			P(0)
		elif k % 2 != 0 and n % 2 != 0:
			P(0)
		else:
			P(1)
		return
	else:
		P(k - n)
		return
t = II()
for i in range(t):
	solve()


import os
from io import BytesIO
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline

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

def ii():
	return int(input())
t = ii()
for _ in range(t):
	(n, k) = lii()
	if n == 0:
		print(k)
	elif n == k:
		print(0)
	elif n < k:
		print(k - n)
	elif n > k:
		if (n - k) % 2 == 0:
			print(0)
		else:
			print(1)


import sys
sys.setrecursionlimit(10000)
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	if k > n:
		print(k - n)
	elif (n + k) % 2 == 0:
		print(0)
	else:
		print(1)


from sys import stdin, stdout

class Input:

	def __init__(self):
		self.lines = stdin.read().splitlines()
		self.idx = 0

	def line(self):
		try:
			return self.lines[self.idx]
		finally:
			self.idx += 1

	def array(self, sep=' ', cast=int):
		return list(map(cast, self.line().split(sep=sep)))

	def known_tests(self):
		(num_of_cases,) = self.array()
		for case in range(num_of_cases):
			yield self

	def unknown_tests(self):
		while self.idx < len(self.lines):
			yield self

class Problem:

	def __init__(self):
		self.oo = float('inf')

	def solve(self, n, k):
		if n < k:
			print(k - n)
		elif (n - k) % 2 == 0:
			print(0)
		else:
			print(1)
try:
	p = Problem()
	for tc in Input().known_tests():
		p.solve(*tc.array())
except Exception as e:
	import traceback
	traceback.print_exc(file=stdout)


for _ in range(0, int(input())):
	l = list(map(int, input().split()))
	k = l[1]
	a = l[0]
	if k >= a:
		print(k - a)
	elif k % 2 == 1 and a % 2 == 1:
		print('0')
	elif k % 2 == 0 and a % 2 == 0:
		print('0')
	else:
		print('1')


testcases = int(input())
for testcase in range(testcases):
	temparr = input()
	temparr = temparr.split()
	a = int(temparr[0])
	k = int(temparr[1])
	ans = 0
	if a == k:
		print(0)
		continue
	if a < k:
		ans = k - a
		print(ans)
		continue
	else:
		total = k + a
		if total & 1 == 0:
			print(0)
		else:
			print(1)


from sys import stdin, stdout
from math import pow, floor, ceil, log2 as log
t = int(stdin.readline())
arr = []
for i in range(t):
	arr.append(str(stdin.readline()))
for i in range(t):
	j = arr[i].find(' ')
	n = int(arr[i][0:j])
	k = int(arr[i][j + 1:])
	if n > k:
		count = 0
		b = int((n + count - k) / 2)
		ch = True
		while ch:
			b = int((n + count - k) / 2)
			if k == abs(2 * b - n - count):
				ch = False
			else:
				count += 1
		print(count)
	else:
		print(k - n)


n = int(input())
for i in range(0, n):
	(a, k) = map(int, input().split())
	if k >= a:
		x = k - a
	else:
		x = 0
		while not (a + k) / 2 % 1 == 0:
			x += 1
			a += x
	print(x)


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())
t = inp()
for i in range(t):
	(a, k) = invr()
	if k > a:
		print(k - a)
	elif k % 2 == a % 2:
		print(0)
	else:
		print(1)


for tc in range(int(input())):
	(a, d) = map(int, input().split())
	if d > a:
		print(d - a)
	else:
		total = a + d
		if total > 0 and total % 2 != 0:
			print(1)
		else:
			print(0)


def answer(n, k):
	if n % 2 == k % 2 and k <= n:
		return 0
	elif n % 2 != k % 2 and k <= n:
		return 1
	else:
		return k - n
	return

def main():
	t = int(input())
	n = [0] * t
	k = [0] * t
	for j in range(t):
		(n[j], k[j]) = [int(i) for i in input().split()]
	for j in range(t):
		print(answer(n[j], k[j]))
main()


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k <= n:
		if k % 2 == 0 and n % 2 == 0 or (k % 2 == 1 and n % 2 == 1):
			print(0)
		else:
			print(1)
	else:
		print(k - n)


def solution(n, k):
	s = n - k
	if s >= 0:
		if s & 1:
			return 1
		else:
			return 0
	else:
		return abs(s)
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	print(solution(n, k))


from sys import stdin, stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()
for _ in range(int(I1())):
	(n, k) = I()
	if n <= k:
		print(k - n)
	elif k == 0:
		if n % 2 == 0:
			print(0)
		else:
			print(1)
	elif n % 2 == 0 and k % 2 != 0 or (n % 2 != 0 and k % 2 == 0):
		print(1)
	else:
		print(0)


import math
for q in range(int(input())):
	(a, b) = map(int, input().split())
	if a >= b:
		if (a + b) % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		print(abs(a - b))


def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = mpos(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum
from math import *
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(k - n)
	elif n + k & 1:
		print(1)
	else:
		print(0)


t = int(input())
c = []
for i in range(t):
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	if k <= n:
		if (n - k) % 2 == 0:
			c.append(0)
		else:
			c.append(1)
	else:
		c.append(k - n)
for k in c:
	print(k)


for i in range(int(input())):
	(N, K) = map(int, input().split())
	if N == K:
		print(0)
	elif N < K:
		print(K - N)
	elif K % 2 == 0 and N % 2 == 0:
		print(0)
	elif K % 2 != 0 and N % 2 != 0:
		print(0)
	else:
		print(1)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n == k:
		print(0)
	elif n <= k:
		x = k - n
		print(x)
	elif n >= k:
		y = (n - k) % 2
		print(y)


n = []
k = []
t = int(input())
for i in range(0, t, 1):
	(n1, k1) = map(int, input().split())
	n.append(n1)
	k.append(k1)
for i in range(0, t, 1):
	if n[i] < k[i]:
		print(k[i] - n[i])
	elif n[i] % 2 == k[i] % 2:
		print(0)
	else:
		print(1)


from sys import stdin
from collections import defaultdict
input = stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().rstrip().split())
	if k > n:
		print(k - n)
	else:
		answer = 0
		if k % 2 == 0 and n % 2 != 0:
			answer += 1
		if k % 2 == 1 and n % 2 != 1:
			answer += 1
		print(answer)


import sys
readline = sys.stdin.buffer.readline

def i1():
	return int(readline())

def mll(n):
	return ([int(s) for s in readline().split()] for i in range(n))
print('\n'.join((str((n - k) % 2 if k < n else k - n) for (n, k) in mll(i1()))))


T = int(input())
for _ in range(T):
	(n, k) = list(map(int, input().split()))
	if n <= k:
		ans = k - n
	else:
		ans = (n + k) % 2
	print(ans)


t = int(input())
for hh in range(0, t):
	(n, k) = [int(x) for x in input().split()]
	if n <= k:
		b = k
		diff = b - n
		print(diff)
	else:
		diff = n - k
		if diff % 2 == 0:
			print(0)
		else:
			print(1)


def solve(a, d):
	if d == 0:
		if a % 2 == 0:
			ans = 0
		else:
			ans = 1
	elif a <= d:
		ans = d - a
	elif a % 2 == 0 and d % 2 == 0 or (a % 2 != 0 and d % 2 != 0):
		ans = 0
	else:
		ans = 1
	print(ans)
n = int(input())
for i in range(n):
	l = list(map(int, input().split()))
	solve(l[0], l[1])


def dummy():
	return 2 * 3 * 4

def solve(n, k):
	div = (n + k) / 2
	if div == int((n + k) / 2):
		print(0)
	else:
		c = int((n + k) / 2)
		div = (n + k) / 2
		ans = 0
		while div != c:
			ans += 1
			n += 1
			c = int((n + k) / 2)
			div = (n + k) / 2
		print(ans)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n < k:
		print(abs(n - k))
	else:
		solve(n, k)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7
mod2 = 998244353

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

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

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	(n, k) = sp()
	if k >= n:
		out(k - n)
		continue
	if k & 1 == n & 1:
		out(0)
		continue
	out(1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	cnt = 0
	if k > n:
		cnt += k - n
		n = k
	if k % 2 != n % 2:
		cnt += 1
	print(cnt)


from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))
t = sInt()
for _ in range(t):
	(n, k) = mInt()
	if k > n:
		print(k - n)
	elif n % 2 == k % 2:
		print(0)
	else:
		print(1)


t = int(input())
for i in range(t):
	(a, k) = map(int, input().split())
	step = 0
	if k >= a:
		print(abs(k - a))
	elif k < a:
		if a % 2 == 0 and k % 2 == 0 or (a % 2 != 0 and k % 2 != 0):
			step = 0
			print(step)
		else:
			step = 1
			print(step)


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

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

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

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]
for _ in range(II()):
	(n, k) = MI()
	ans = abs(n - k)
	if n >= k:
		ans = min(ans, (n - k) % 2)
	print(ans)


for i in range(int(input())):
	(m, n) = map(int, input().split())
	if m % 2 == 0:
		if n % 2 == 0 and m >= n:
			print('0')
		elif n % 2 != 0 and m >= n:
			print('1')
		else:
			print(abs(m - n))
	elif n % 2 != 0 and m >= n:
		print('0')
	elif n % 2 == 0 and m >= n:
		print('1')
	else:
		print(abs(m - n))


for _ in range(int(input())):
	(n, k) = list((int(x) for x in input().split()))
	if n >= k:
		if (n - k) % 2 != 0:
			print(1)
		else:
			print(0)
	else:
		print(k - n)


from math import ceil

def get_ans(n, k):
	if k > n:
		return k - n
	elif (k + n) % 2 == 0:
		return 0
	else:
		return 1
t = int(input())
anss = []
for _ in range(t):
	inp = list(map(int, input().split()))
	(n, k) = (inp[0], inp[1])
	anss.append(get_ans(n, k))
for i in anss:
	print(i)


def get_steps(n, k):
	steps = 0
	if k == 0:
		if n % 2 == 0:
			return steps
		else:
			steps = 1
			return steps
	elif k == n:
		return steps
	elif k % 2 == n % 2:
		if n >= k:
			return steps
		else:
			steps = k - n
			return steps
	elif k % 2 != n % 2:
		if n >= k:
			steps = 1
			return steps
		else:
			steps = k - n
			return steps
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	r = get_steps(n, k)
	print(r)


from collections import deque
from collections import OrderedDict
import math
import sys
import os
import threading
import bisect
import operator
import heapq
from atexit import register
from io import BytesIO
import io
from sys import stdin, stdout
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(k - n)
	elif n % 2 == 0:
		if k % 2 == 0:
			print(0)
		else:
			print(1)
	elif k % 2 == 1:
		print(0)
	else:
		print(1)
sys.exit(0)

class Person:

	def __init__(self, name, age):
		self.name = name
		self.age = age
p1 = Person('heelo', 27)
print(help(Person))
age = 26
name = 'Swaroop'
print('Возрас {} -- {} лет'.format(name, age))
print(help(object))


for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	if n >= k:
		if (n + k) % 2 == 0:
			print(0)
		else:
			print(1)
		continue
	print(abs(n - k))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	b = False
	if k > n:
		print(k - n)
	elif k % 2 == 0 and n % 2 == 0 or (k % 2 == 1 and n % 2 == 1):
		print(0)
	else:
		print(1)


t = int(input())
for i in range(t):
	nm = list(map(int, input().split()))
	n = nm[0]
	m = nm[1]
	if n < m:
		selisih = m - n
		print(selisih)
	elif n == m:
		print(0)
	elif n > m:
		if n % 2 == 0 and m % 2 != 0:
			print(1)
		elif n % 2 != 0 and m % 2 == 0:
			print(1)
		else:
			print(0)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n >= k:
		if n & 1 == k & 1:
			print(0)
		else:
			print(1)
			1
	else:
		print(k - n)


T = int(input())
for i in range(T):
	(n, k) = list(map(int, input().split()))
	if k > n:
		print(k - n)
	else:
		print((n + k) % 2)


from sys import stdin, stdout
input = stdin.readline

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

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

def gets():
	return input('')

def geta():
	return int(input())

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

def solve():
	for _ in range(geta()):
		(n, k) = geti()
		if k >= n:
			print(k - n)
		elif n & 1 ^ k & 1:
			print(1)
		else:
			print(0)
solve()


def ans(n, k):
	if n == 0 and k == 0:
		return 0
	if k == 0:
		return n % 2
	if k >= n:
		return k - n
	if k < n:
		if k % 2 == 0 and n % 2 == 0:
			return 0
		elif k % 2 == 1 and n % 2 == 1:
			return 0
		else:
			return 1
m = int(input())
for i in range(m):
	arr = input().split()
	a = []
	for i in arr:
		a.append(int(i))
	n = a[0]
	k = a[1]
	print(ans(n, k))


def ans1(a, k):
	if (k + a) % 2 == 1:
		return 1
	return 0

def ans(a, k):
	if k > a:
		return k - a
	if k == a:
		return 0
	return ans1(a, k)
T = int(input())
for t in range(T):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	print(ans(n, k))


t = int(input())
for _ in range(0, t):
	(a, k) = list(map(lambda x: int(x), input().split()))
	if k < a:
		if (a + k) % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		print(k - a)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	x = (k + n) / 2
	y = int(x)
	if x <= n:
		if x == y:
			print(0)
		else:
			print(1)
	else:
		print(abs(n - k))


def get_order_of(end, k):
	n = end
	(d, u) = (0, end)
	if end == k:
		return True
	if end == 0:
		return False
	while d < u - 1:
		mid = (d + u) // 2
		if int(abs(n - 2 * mid)) < int(k):
			u = mid
		elif int(abs(n - 2 * mid)) > int(k):
			d = mid
		else:
			return True
	return False
t = int(input())
import copy
for q in range(t):
	(n, k) = tuple(map(int, input().split()))
	m = max(n, k)
	pm = 0
	while True:
		if get_order_of(n + pm, k) is True:
			break
		elif n - pm > 0 and get_order_of(n - pm, k) is True:
			break
		elif n < k:
			pm += abs(k - n)
		else:
			pm += 1
	print(pm)


from sys import stdin, stdout
import math, queue, heapq
fastinput = stdin.readline
fastout = stdout.write
t = int(fastinput())
while t:
	t -= 1
	(n, k) = map(int, fastinput().split())
	if k <= n and (n - k) % 2 == 0:
		print(0)
	elif k <= n + 1:
		print(1)
	else:
		print(abs(n - k))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	count = 0
	if k > n:
		print(k - n)
		continue
	while (n - k) % 2 != 0:
		count += 1
		n -= 1
	print(count)


def strategy(n, k):
	if n - k <= 0:
		return k - n
	else:
		return (n - k) % 2
res = []
n = int(input())
for i in range(n):
	(n, k) = [int(x) for x in input().split(' ')]
	res.append(strategy(n, k))
for r in res:
	print(r)


import sys
for i in range(0, int(sys.stdin.readline())):
	nk = list(map(int, sys.stdin.readline().split()))
	n = nk[0]
	k = nk[1]
	if n >= k:
		if n % 2 == k % 2:
			sys.stdout.write('0')
		else:
			sys.stdout.write('1')
	else:
		sys.stdout.write(str(k - n))
	sys.stdout.write('\n')


number_of_test_cases = int(input())
for _ in range(number_of_test_cases):
	(n, K) = [int(_) for _ in input().split()]
	if n == K:
		print(0)
	elif n < K:
		print(K - n)
	else:
		i = 0
		while (n - K) % 2 and (n + K) % 2:
			n += 1
			i += 1
		print(i)


from math import ceil
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if n > m:
		print(1 if abs(m - n) % 2 != 0 else 0)
	else:
		print(m - n)


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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def dfs(graph, start=0):
	n = len(graph)
	dp = [0] * n
	(visited, finished) = ([False] * n, [False] * n)
	stack = [start]
	while stack:
		start = stack[-1]
		if not visited[start]:
			visited[start] = True
			for child in graph[start]:
				if not visited[child]:
					stack.append(child)
		else:
			stack.pop()
			dp[start] += 1
			for child in graph[start]:
				if finished[child]:
					dp[start] += dp[child]
			finished[start] = True
	return (visited, dp)
from collections import deque
for _ in range(int(input()) if True else 1):
	(n, k) = map(int, input().split())
	print(k - n if k > n else (n - k) % 2)


x = int(input())
for i in range(x):
	(a, b) = map(int, input().split())
	t1 = abs(a - b)
	if a >= b:
		t1 = min(t1, (a + b) % 2)
	print(t1)


def main(n, k):
	if k >= n:
		re = k - n
	else:
		res1 = k % 2
		res2 = n % 2
		re = (res1 + res2) % 2
	return re
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	ans = main(n, k)
	print(ans)


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
for ii in range(int(input())):
	(n, k) = map(int, input().split())
	if n < k:
		print(k - n)
		continue
	if n % 2 == k % 2:
		print(0)
	else:
		print(1)


t = int(input())
for _ in range(t):
	(a, k) = map(int, input().split())
	ans = 10 ** 9
	if a >= k:
		if (a + k) % 2 == 0:
			ans = 0
		else:
			ans = 1
	ans = min(abs(a - k), ans)
	print(ans)


n = int(input())
for i in range(n):
	(x, y) = [int(x) for x in input().split()]
	count = 0
	if x % 2 == 0:
		if y % 2 == 0:
			if x < y:
				count = count + y - x
		if y % 2 != 0:
			if x > y:
				count = count + 1
			if x < y:
				count = count + y - x
	if x % 2 != 0:
		if y % 2 != 0:
			if x < y:
				count = count + y - x
		if y % 2 == 0:
			if x > y:
				count = count + 1
			if x < y:
				count = count + y - x
	print(count)


nbtest = int(input())
x = 0
for i in range(nbtest):
	list1 = list(map(int, input().split()))
	if list1[0] <= list1[1]:
		x = list1[1] - list1[0]
	elif (list1[0] - list1[1]) % 2 == 0:
		x = 0
	else:
		x = 1
	print(x)
	x = 0


import sys

def uno():
	return int(sys.stdin.readline().strip())

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

def tres():
	return map(int, sys.stdin.readline().strip().split())

def cuatro():
	return sys.stdin.readline().strip().split()

def pmod(b, x, m):
	res = 1
	while x:
		if x & 1:
			res = res * b % m
		x >>= 1
		b = b * b % m
	return res

def inv(a, m):
	return pmod(a, m - 2, m)
for _ in range(uno()):
	(a, k) = tres()
	if a <= k:
		print(abs(a - k))
	else:
		print(abs(a - k) & 1)


t = int(input())
while t:
	(n, k) = map(int, input().split())
	ans = 10 ** 9
	if n <= k:
		ans = min(ans, k - n)
	elif (n - k) % 2 == 0:
		ans = 0
	else:
		ans = min(ans, 1)
	print(ans)
	t -= 1


import math

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))

def solve():
	(n, k) = Read.list_int()
	if n >= k:
		l = n - k
		if l % 2 == 0:
			print('0')
		else:
			print('1')
	else:
		print(k - n)
query_count = Read.int()
while query_count:
	query_count -= 1
	solve()


def check(n, k):
	if k >= n:
		print(k - n)
	elif k % 2 == 0:
		if n % 2 == 0:
			print('0')
		else:
			print('1')
	elif n % 2 == 0:
		print('1')
	else:
		print('0')
T = int(input())
for i in range(0, T):
	(n, k) = input().split(' ')
	n = int(n)
	k = int(k)
	check(n, k)


import sys
t = int(sys.stdin.readline().strip())
for _ in range(t):
	(n, k) = map(int, sys.stdin.readline().strip().split())
	x = max(n, k) + 1
	if n == k:
		x = 0
	elif k - n < 0:
		for y in range((n - k) // 2, max(n, k) + 1):
			res = k - n + 2 * y
			if res >= 0:
				if res < x:
					x = res
					break
	else:
		x = k - n
	print(x)


t = int(input())
while t:
	(a, k) = list(map(int, input().split()))
	if k < a:
		if (a - k) % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		print(abs(k - a))
	t -= 1


tc = int(input())
while tc > 0:
	tc -= 1
	(a, b) = map(int, input().split())
	if b > a:
		print(b - a)
	elif a % 2 == 0 and b % 2 == 1 or (a % 2 == 1 and b % 2 == 0):
		print('1')
	else:
		print('0')


import sys
input = sys.stdin.readline
t = int(input())
for tt in range(t):
	ans = 0
	(n, k) = map(int, input().split())
	if n < k or n % 2 != k % 2:
		if n < k:
			ans = k - n
		else:
			ans = 1
		print(ans)
	else:
		print(0)


test = int(input())
for i in range(0, test):
	nk = input().split()
	a = int(nk[0])
	k = int(nk[1])
	print(max(k - a, k + a & 1))


import sys

def get_ints():
	return map(int, I().split())

def get_list():
	return list(map(int, I().split()))

def I():
	return sys.stdin.readline().strip()
for _ in range(int(I())):
	(n, k) = get_ints()
	if k > n:
		print(abs(n - k))
	else:
		print(abs(n - k) % 2)


import math
t = int(input())
while t > 0:
	t -= 1
	s = list(map(int, input().split()))
	n = s[0]
	k = s[1]
	if k >= n:
		print(k - n)
	elif k < n:
		print((n - k) % 2)


from sys import stdin, stdout
try:
	t = int(input())
	for i in range(t):
		(n, k) = map(int, input().split())
		if n == k:
			print(0)
		elif k > n:
			print(k - n)
		elif k % 2 == 0 and n % 2 == 0 or (k % 2 != 0 and n % 2 != 0):
			print(0)
		else:
			print(1)
except:
	pass


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	val = abs(n - k)
	b = val // 2 + val % 2
	val2 = 2 * b + k
	val2 = abs(n - val2)
	print(min(val, val2))


ct = int(input())
while ct > 0:
	ct -= 1
	res = int(100000000.0)
	(n, k) = list(map(int, input().split()))
	if n == k:
		print(0)
	elif n < k:
		print(k - n)
	elif n % 2 == k % 2:
		print(0)
	else:
		print(1)