There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. 

You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each team, instead he thought that absolute difference between number of wins of first and second team will be d_1 and that of between second and third team will be d_2.

You don't want any of team win the tournament, that is each team should have the same number of wins after n games. That's why you want to know: does there exist a valid tournament satisfying the friend's guess such that no team will win this tournament?

Note that outcome of a match can not be a draw, it has to be either win or loss.


-----Input-----

The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 10^5).

Each of the next t lines will contain four space-separated integers n, k, d_1, d_2 (1 ≤ n ≤ 10^12; 0 ≤ k ≤ n; 0 ≤ d_1, d_2 ≤ k) — data for the current test case.


-----Output-----

For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).


-----Examples-----
Input
5
3 0 0 0
3 3 0 0
6 4 1 0
6 3 3 0
3 3 3 2

Output
yes
yes
yes
no
no



-----Note-----

Sample 1. There has not been any match up to now (k = 0, d_1 = 0, d_2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win.

Sample 2. You missed all the games (k = 3). As d_1 = 0 and d_2 = 0, and there is a way to play three games with no winner of tournament (described in the previous sample), the answer is "yes".

Sample 3. You missed 4 matches, and d_1 = 1, d_2 = 0. These four matches can be: 1-2 (win 2), 1-3 (win 3), 1-2 (win 1), 1-3 (win 1). Currently the first team has 2 wins, the second team has 1 win, the third team has 1 win. Two remaining matches can be: 1-2 (win 2), 1-3 (win 3). In the end all the teams have equal number of wins (2 wins).

Difficulty: MEDIUM_HARD
Tags: Mathematics

Implementation

Complete search
Skill types: Complete search

Starter code:

Solutions:
def check(n, k, d1, d2):
	if (k - d1 - d2) % 3 != 0:
		return False
	y = (k - d1 - d2) // 3
	return min(y + d1, y, y + d2) >= 0 and max(y + d1, y, y + d2) <= n // 3
t = int(input())
all_res = []
for _ in range(t):
	(n, k, d1, d2) = map(int, input().split())
	if n % 3 != 0:
		all_res += ['no']
	elif check(n, k, d1, d2) or check(n, k, -d1, d2) or check(n, k, d1, -d2) or check(n, k, -d1, -d2):
		all_res += ['yes']
	else:
		all_res += ['no']
print('\n'.join(all_res))


import sys

def check(a, b, c, n, k):
	need = n // 3
	return n - k == need - a + (need - b) + (need - c) and a <= need and (b <= need) and (c <= need) and (a >= 0) and (b >= 0) and (c >= 0)
for tc in range(int(sys.stdin.readline())):
	(n, k, d1, d2) = map(int, sys.stdin.readline().split())
	if n % 3 != 0:
		print('no')
		continue
	ans = False
	a = k - 2 * d1 - d2
	if a % 3 == 0:
		a //= 3
		ans |= check(a, a + d1, a + d1 + d2, n, k)
	a = k + d2 - 2 * d1
	if a % 3 == 0:
		a //= 3
		ans |= check(a, a + d1, a + d1 - d2, n, k)
	a = k + 2 * d1 + d2
	if a % 3 == 0:
		a //= 3
		ans |= check(a, a - d1, a - d1 - d2, n, k)
	a = k - d2 + 2 * d1
	if a % 3 == 0:
		a //= 3
		ans |= check(a, a - d1, a - d1 + d2, n, k)
	print('yes' if ans else 'no')


from sys import *
t = int(stdin.readline())
for i in range(t):
	(n, k, d1, d2) = (int(z) for z in stdin.readline().split())
	vars = ((2 * d1 + d2, 2 * d2 + d1), (2 * d2 + d1, 2 * d1 + d2), (2 * max(d1, d2) - min(d1, d2), d1 + d2), (d1 + d2, 2 * max(d1, d2) - min(d1, d2)))
	y = False
	for i in vars:
		if i[0] <= k and i[0] % 3 == k % 3 and (n - k - i[1] >= 0) and ((n - i[1] - k) % 3 == 0):
			print('yes')
			y = True
			break
	if not y:
		print('no')


from sys import stdin
from math import fabs
t = int(stdin.readline())
for _ in range(t):
	(n, k, d1, d2) = map(int, stdin.readline().split())
	flg = False
	w = k + 2 * d1 + d2
	a = w // 3
	if w >= 0 and w % 3 == 0 and (a >= d1 + d2) and (2 * d1 + d2 <= n - k) and ((n - k - 2 * d1 - d2) % 3 == 0):
		flg = True
	w = k + 2 * d1 - d2
	a = w // 3
	if w >= 0 and w % 3 == 0 and (a >= d1) and (a >= d1 - d2):
		req = 0
		if d2 < d1:
			req = 2 * d1 - d2
		else:
			req = 2 * d2 - d1
		if n - k >= req and (n - k - req) % 3 == 0:
			flg = True
	w = k - 2 * d1 + d2
	a = w // 3
	if w >= 0 and w % 3 == 0 and (a >= d2 - d1) and (d1 + d2 <= n - k) and ((n - k - d1 - d2) % 3 == 0):
		flg = True
	w = k - 2 * d1 - d2
	if w >= 0 and w % 3 == 0 and (2 * d2 + d1 <= n - k) and ((n - k - 2 * d2 - d1) % 3 == 0):
		flg = True
	if n % 3:
		flg = False
	if flg:
		print('yes')
	else:
		print('no')


t = int(input())
for l in range(t):
	(n, k, d1, d2) = map(int, input().split())
	if n % 3 != 0:
		print('no')
		continue
	n = n // 3
	ok = False
	for i in [-1, 1]:
		for j in [-1, 1]:
			tmp = k
			tmp -= d1 * i
			tmp -= d1 * i
			tmp -= d2 * j
			if tmp % 3 != 0:
				continue
			if tmp < 0:
				continue
			tmp = tmp // 3
			x1 = tmp
			x2 = x1 + d1 * i
			x3 = x2 + d2 * j
			if x1 < 0 or x2 < 0 or x3 < 0:
				continue
			if x1 <= n and x2 <= n and (x3 <= n):
				ok = True
				break
	if ok:
		print('yes')
	else:
		print('no')


for i in range(int(input())):
	(n, u, a, b) = map(int, input().split())
	if n % 3:
		print('no')
	else:
		if a > b:
			(a, b) = (b, a)
		(p, q) = (a + b, 2 * b - a)
		(s, r, v) = (p + a, p + b, n - u)
		t = [(p, q), (q, p), (s, r), (r, s)]
		print('no' if all((x > u or (x - u) % 3 or y > v or (y - v) % 3 for (x, y) in t)) else 'yes')


t = int(input())
ret = []
while t > 0:
	t -= 1
	(n, k, d1, d2) = map(int, input().split())
	y1 = (k - (d1 - d2)) // 3
	x1 = y1 + d1
	z1 = y1 - d2
	ans1 = 2 * x1 - (z1 + y1)
	if x1 + y1 + z1 == k and min(z1, y1) >= 0 and (ans1 <= n - k) and ((n - k - ans1) % 3 == 0):
		ret.append('yes')
		continue
	y1 = (k - (d1 + d2)) // 3
	x1 = y1 + d1
	z1 = y1 + d2
	if d1 >= d2:
		ans1 = 2 * x1 - (y1 + z1)
	else:
		ans1 = 2 * z1 - (y1 + x1)
	if x1 + y1 + z1 == k and y1 >= 0 and (ans1 <= n - k) and ((n - k - ans1) % 3 == 0):
		ret.append('yes')
		continue
	y1 = (k - (d2 - d1)) // 3
	x1 = y1 - d1
	z1 = y1 + d2
	ans1 = 2 * z1 - (x1 + y1)
	if x1 + y1 + z1 == k and min(x1, y1) >= 0 and (ans1 <= n - k) and ((n - k - ans1) % 3 == 0):
		ret.append('yes')
		continue
	y1 = (k + (d2 + d1)) // 3
	x1 = y1 - d1
	z1 = y1 - d2
	ans1 = 2 * y1 - (x1 + z1)
	if x1 + y1 + z1 == k and min(x1, z1) >= 0 and (ans1 <= n - k) and ((n - k - ans1) % 3 == 0):
		ret.append('yes')
		continue
	ret.append('no')
print(*ret, sep='\n')


for i in range(int(input())):
	(n, k, d1, d2) = map(int, input().split())
	flag = True
	if flag:
		c = (k - d1 - 2 * d2) // 3
		b = c + d2
		a = b + d1
		if a >= 0 and b >= 0 and (c >= 0) and (k == a + b + c):
			v = [a, b, c]
			v.sort(reverse=True)
			if n - k >= v[0] - v[1] + v[0] - v[2] and (n - k - (v[0] - v[1] + v[0] - v[2])) % 3 == 0:
				print('yes')
				flag = False
	if flag:
		c = (k - d1 + 2 * d2) // 3
		b = c - d2
		a = b + d1
		if a >= 0 and b >= 0 and (c >= 0) and (k == a + b + c):
			v = [a, b, c]
			v.sort(reverse=True)
			if n - k >= v[0] - v[1] + v[0] - v[2] and (n - k - (v[0] - v[1] + v[0] - v[2])) % 3 == 0:
				print('yes')
				flag = False
	if flag:
		c = (k + d1 - 2 * d2) // 3
		b = c + d2
		a = b - d1
		if a >= 0 and b >= 0 and (c >= 0) and (k == a + b + c):
			v = [a, b, c]
			v.sort(reverse=True)
			if n - k >= v[0] - v[1] + v[0] - v[2] and (n - k - (v[0] - v[1] + v[0] - v[2])) % 3 == 0:
				print('yes')
				flag = False
	if flag:
		c = (k + d1 + 2 * d2) // 3
		b = c - d2
		a = b - d1
		if a >= 0 and b >= 0 and (c >= 0) and (k == a + b + c):
			v = [a, b, c]
			v.sort(reverse=True)
			if n - k >= v[0] - v[1] + v[0] - v[2] and (n - k - (v[0] - v[1] + v[0] - v[2])) % 3 == 0:
				print('yes')
				flag = False
	if flag:
		print('no')


for t in range(int(input())):
	(n, k, d1, d2) = map(int, input().split())
	flag = False
	x = (k + 2 * d1 + d2) // 3
	(a, b, c) = (x, x - d1, x - d1 - d2)
	n1 = n // 3
	flag1 = True
	if n % 3 != 0 or abs(n1 - a) + abs(n1 - b) + abs(n1 - c) != n - k or a + b + c != k or (a > n1) or (b > n1) or (c > n1) or (a < 0) or (b < 0) or (c < 0):
		flag1 = False
	flag = flag or flag1
	x = (k + 2 * d1 - d2) // 3
	(a, b, c) = (x, x - d1, x - d1 + d2)
	n1 = n // 3
	flag1 = True
	if n % 3 != 0 or abs(n1 - a) + abs(n1 - b) + abs(n1 - c) != n - k or a + b + c != k or (a > n1) or (b > n1) or (c > n1) or (a < 0) or (b < 0) or (c < 0):
		flag1 = False
	flag = flag or flag1
	x = (k - 2 * d1 + d2) // 3
	(a, b, c) = (x, x + d1, x + d1 - d2)
	n1 = n // 3
	flag1 = True
	if n % 3 != 0 or abs(n1 - a) + abs(n1 - b) + abs(n1 - c) != n - k or a + b + c != k or (a > n1) or (b > n1) or (c > n1) or (a < 0) or (b < 0) or (c < 0):
		flag1 = False
	flag = flag or flag1
	x = (k - 2 * d1 - d2) // 3
	(a, b, c) = (x, x + d1, x + d1 + d2)
	n1 = n // 3
	flag1 = True
	if n % 3 != 0 or abs(n1 - a) + abs(n1 - b) + abs(n1 - c) != n - k or a + b + c != k or (a > n1) or (b > n1) or (c > n1) or (a < 0) or (b < 0) or (c < 0):
		flag1 = False
	flag = flag or flag1
	if flag:
		print('yes')
	else:
		print('no')


q = int(input())
while q > 0:
	(n, k, d1, d2) = map(int, input().split())
	if d1 > d2:
		(d1, d2) = (d2, d1)
	if k - 2 * d1 - d2 >= 0 and (k - 2 * d1 - d2) % 3 == 0 and (n - k - d1 - 2 * d2 >= 0) and ((n - k - d1 - 2 * d2) % 3 == 0):
		print('yes')
	elif k - 2 * d2 - d1 >= 0 and (k - 2 * d2 - d1) % 3 == 0 and (n - k - d2 - 2 * d1 >= 0) and ((n - k - d2 - 2 * d1) % 3 == 0):
		print('yes')
	elif k - 2 * d2 + d1 >= 0 and (k - 2 * d2 + d1) % 3 == 0 and (n - k - d2 - d1 >= 0) and ((n - k - d2 - d1) % 3 == 0):
		print('yes')
	elif k - d1 - d2 >= 0 and (k - d1 - d2) % 3 == 0 and (n - k - 2 * d2 + d1 >= 0) and ((n - k - 2 * d2 + d1) % 3 == 0):
		print('yes')
	else:
		print('no')
	q -= 1


from sys import *
t = int(stdin.readline())
mm = 0
for i in range(t):
	(n, k, d1, d2) = (int(z) for z in stdin.readline().split())
	mm = 2 * max(d1, d2) - min(d1, d2)
	if k - 2 * d1 - d2 >= 0 and (k - 2 * d1 - d2) % 3 == 0 and (n - 2 * d2 - d1 - k >= 0) and ((n - 2 * d2 - d1 - k) % 3 == 0) or (k - 2 * d2 - d1 >= 0 and (k - 2 * d2 - d1) % 3 == 0 and (n - 2 * d1 - d2 - k >= 0) and ((n - 2 * d1 - d2 - k) % 3 == 0)) or (k - d1 - d2 >= 0 and (k - d1 - d2) % 3 == 0 and (n - mm - k >= 0) and ((n - mm - k) % 3 == 0)) or (k - mm >= 0 and (k - mm) % 3 == 0 and (n - d1 - d2 - k >= 0) and ((n - d1 - d2 - k) % 3 == 0)):
		print('yes')
	else:
		print('no')


import sys
import math
MAXNUM = math.inf
MINNUM = -1 * math.inf
ASCIILOWER = 97
ASCIIUPPER = 65

def getInt():
	return int(sys.stdin.readline().rstrip())

def getInts():
	return map(int, sys.stdin.readline().rstrip().split(' '))

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

def printOutput(ans):
	sys.stdout.write(ans + '\n')

def solve(n, k, d1, d2):
	possans = []
	amc = d1 + d2
	subtotal = k + amc + d1
	if subtotal % 3 == 0:
		a = subtotal // 3
		possans.append((a, a - d1, a - d1 - d2))
	amc = d1 + d2
	subtotal = k - amc
	if subtotal % 3 == 0:
		b = subtotal // 3
		possans.append((b + d1, b, b + d2))
	amc = d1 + d2
	subtotal = k + amc
	if subtotal % 3 == 0:
		b = subtotal // 3
		possans.append((b - d1, b, b - d2))
	amc = d1 + d2
	subtotal = k + amc + d2
	if subtotal % 3 == 0:
		c = subtotal // 3
		possans.append((c - d2 - d1, c - d2, c))
	for t in possans:
		(a, b, c) = t
		if a + b + c != k or a < 0 or b < 0 or (c < 0):
			continue
		h = max(a, b, c)
		mingames = h - a + (h - b) + (h - c)
		remgames = n - k
		if mingames <= remgames and (remgames - mingames) % 3 == 0:
			return 'yes'
	return 'no'

def readinput():
	tc = getInt()
	for _ in range(tc):
		(n, k, d1, d2) = getInts()
		printOutput(solve(n, k, d1, d2))
readinput()


t = int(input())
for i in range(t):
	(n, k, a, b) = map(int, input().split())
	if n % 3 != 0:
		print('no')
	else:
		for i in range(2):
			for j in range(2):
				flagf = False
				if i == 0:
					a1 = a
				else:
					a1 = -a
				if j == 0:
					b1 = b
				else:
					b1 = -b
				t2 = (k - a1 + b1) / 3
				t1 = a1 + t2
				t3 = t2 - b1
				flag1 = False
				flag2 = False
				if (k - a1 + b1) % 3 == 0 and t1 >= 0 and (t2 >= 0) and (t3 >= 0):
					if t1 <= n / 3 and t2 <= n / 3 and (t3 <= n / 3):
						if i == 0 and t1 >= t2:
							flag1 = True
						elif i == 1 and t1 < t2:
							flag1 = True
						if j == 0 and t2 >= t3:
							flag2 = True
						elif j == 1 and t2 < t3:
							flag2 = True
				if flag1 and flag2:
					if t1 == t2 and t2 == t3 and ((n - k) % 3 == 0):
						flagf = True
						break
					else:
						v = [t1, t2, t3]
						v = sorted(v)
						faltam = n - k
						faltam -= v[2] - v[1]
						faltam -= v[2] - v[0]
						if faltam < 0:
							break
						elif faltam == 0 or faltam % 3 == 0:
							flagf = True
							break
			if flagf:
				print('yes')
				break
		else:
			print('no')


from sys import stdin

def solve(n, k, d1, d2):
	if (d1 + 2 * d2 + k) % 3 != 0:
		return False
	c = (d1 + 2 * d2 + k) // 3
	a = c - d1 - d2
	b = k - a - c
	if a >= 0 and b >= 0 and (c >= 0) and (a + b + c == k):
		_max = max(a, b, c)
		diff = sum((_max - e for e in [a, b, c]))
		d = n - k
		if d >= diff and (d - diff) % 3 == 0:
			return True
	return False

def main():
	test = stdin.readlines()
	output = []
	for i in range(1, int(test[0]) + 1):
		(n, k, d1, d2) = map(int, test[i].split())
		for (i, j) in [(-1, -1), (-1, 1), (1, -1), (1, 1)]:
			if solve(n, k, i * d1, j * d2):
				output.append('yes')
				break
		else:
			output.append('no')
	print('\n'.join(output))
main()


from sys import stdin

def solve(n, k, d1, d2):
	d = n - k
	c1 = (k - d1 + 2 * d2) // 3
	a1 = d1 - d2 + c1
	b1 = k - a1 - c1
	c2 = (k - d1 - 2 * d2) // 3
	a2 = d1 + d2 + c2
	b2 = k - a2 - c2
	c3 = (k + d1 - 2 * d2) // 3
	a3 = c3 + d2 - d1
	b3 = k - a3 - c3
	c4 = (k + d1 + 2 * d2) // 3
	a4 = c4 - d1 - d2
	b4 = k - a4 - c4
	if c1 * 3 == 2 * d2 - d1 + k and a1 >= 0 and (b1 >= 0) and (c1 >= 0):
		_max = max(a1, b1, c1)
		diff = sum((_max - e for e in [a1, b1, c1]))
		if d >= diff and (d - diff) % 3 == 0:
			return True
	if c2 * 3 == k - d1 - 2 * d2 and a2 >= 0 and (b2 >= 0) and (c2 >= 0):
		_max = max(a2, b2, c2)
		diff = sum((_max - e for e in [a2, b2, c2]))
		if d >= diff and (d - diff) % 3 == 0:
			return True
	if c3 * 3 == k + d1 - 2 * d2 and a3 >= 0 and (b3 >= 0) and (c3 >= 0):
		_max = max(a3, b3, c3)
		diff = sum((_max - e for e in [a3, b3, c3]))
		if d >= diff and (d - diff) % 3 == 0:
			return True
	if c4 * 3 == k + d1 + 2 * d2 and a4 >= 0 and (b4 >= 0) and (c4 >= 0):
		_max = max(a4, b4, c4)
		diff = sum((_max - e for e in [a4, b4, c4]))
		if d >= diff and (d - diff) % 3 == 0:
			return True
	return False

def main():
	test = stdin.readlines()
	output = []
	for i in range(1, int(test[0]) + 1):
		ans = 'yes' if solve(*map(int, test[i].split())) else 'no'
		output.append(ans)
	print('\n'.join(output))
main()


t = int(input())
for i in range(t):
	(n, k, d1, d2) = map(int, input().split())
	m = d1 + d2
	mm = 2 * max(d1, d2) - min(d1, d2)
	mmm = 2 * d1 + d2
	mmmm = 2 * d2 + d1
	if k - mmm >= 0 and (k - mmm) % 3 == 0 and (n - mmmm - k >= 0) and ((n - mmmm - k) % 3 == 0) or (k - mmmm >= 0 and (k - mmmm) % 3 == 0 and (n - mmm - k >= 0) and ((n - mmm - k) % 3 == 0)) or (k - m >= 0 and (k - m) % 3 == 0 and (n - mm - k >= 0) and ((n - mm - k) % 3 == 0)) or (k - mm >= 0 and (k - mm) % 3 == 0 and (n - m - k >= 0) and ((n - m - k) % 3 == 0)):
		print('yes')
	else:
		print('no')


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

def calc(a, b, c, r):
	if a < 0 or b < 0 or c < 0:
		return False
	temp = [a, b, c]
	temp.sort(reverse=True)
	(a, b, c) = temp
	if a > b and a > c:
		x = a - b
		y = a - c
		r -= x + y
		if r < 0:
			return False
		if r % 3 == 0:
			return True
		else:
			return False
	if a == b:
		if b == c:
			return r % 3 == 0
		x = b - c
		r -= x
		if r < 0:
			return False
		return r % 3 == 0

def main():
	for case in range(int(input())):
		(n, k, d1, d2) = [int(x) for x in input().split()]
		possible = False
		s = k + d1 + d2 + d1
		if s % 3 == 0:
			a = s // 3
			b = a - d1
			c = b - d2
			possible = possible or calc(a, b, c, n - k)
		s = k + d1 + d1 - d2
		if s % 3 == 0:
			a = s // 3
			b = a - d1
			c = b + d2
			possible = possible or calc(a, b, c, n - k)
		s = k - d1 - d1 + d2
		if s % 3 == 0:
			a = s // 3
			b = a + d1
			c = b - d2
			possible = possible or calc(a, b, c, n - k)
		s = k - d1 - d1 - d2
		if s % 3 == 0:
			a = s // 3
			b = a + d1
			c = b + d2
			possible = possible or calc(a, b, c, n - k)
		if possible:
			print('yes')
		else:
			print('no')
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()


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
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, d1, d2) = L()
	if n % 3 != 0:
		print('no')
		continue
	a = 2 * d1 + d2 + k
	a = a * (-1 if a % 3 else 1) // 3
	b = a - d1
	c = b - d2
	if 0 <= a <= n // 3 and 0 <= b <= n // 3 and (0 <= c <= n // 3):
		print('yes')
		continue
	b = d1 + d2 + k
	b = b * (-1 if b % 3 else 1) // 3
	a = b - d1
	c = b - d2
	if 0 <= a <= n // 3 and 0 <= b <= n // 3 and (0 <= c <= n // 3):
		print('yes')
		continue
	b = k - d1 - d2
	if b < 0:
		b = n ** 2
	b = b * (-1 if b % 3 else 1) // 3
	a = b + d1
	c = b + d2
	if 0 <= a <= n // 3 and 0 <= b <= n // 3 and (0 <= c <= n // 3):
		print('yes')
		continue
	b = +d1 - d2 + k
	if b < 0:
		b = n ** 2
	b = b * (-1 if b % 3 else 1) // 3
	a = b - d1
	c = b + d2
	if 0 <= a <= n // 3 and 0 <= b <= n // 3 and (0 <= c <= n // 3):
		print('yes')
		continue
	print('no')
endtime = time.time()


read = lambda : map(int, input().split())
f = lambda x, y, a, b: x > a or y > b or (a - x) % 3 or (b - y) % 3
g = lambda x, y, a, b: f(x, y, a, b) and f(x, y, b, a)
t = int(input())
for i in range(t):
	(n, k, d1, d2) = read()
	r = n - k
	d = d1 + d2
	p = 2 * d2 - d1 if d2 > d1 else 2 * d1 - d2
	print('no' if g(d, p, k, r) and g(d + d1, d + d2, k, r) else 'yes')


import itertools
import sys
for _ in range(int(input())):
	(n, k, d1, d2) = map(int, str.split(sys.stdin.readline()))
	for (s1, s2) in itertools.product((1, -1), repeat=2):
		(cd1, cd2) = (d1 * s1, d2 * s2)
		w2 = k - cd1 + cd2
		if w2 % 3 != 0:
			continue
		w2 //= 3
		w1 = w2 + cd1
		w3 = w2 - cd2
		if w1 >= 0 and w2 >= 0 and (w3 >= 0):
			d = n - k
			mw = max((w1, w2, w3))
			nw = 3 * mw - w1 - w2 - w3
			if d >= nw and (d - nw) % 3 == 0:
				print('yes')
				break
	else:
		print('no')


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

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 10 ** 9 + 7
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

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()]

def check(d1, d2):
	wa = 0
	wb = 0
	wc = 0
	wa = 2 * d1 + d2 + k
	if wa % 3:
		return False
	wa //= 3
	wb = wa - d1
	wc = wb - d2
	if wa < 0 or wb < 0 or wc < 0:
		return False
	(wa, wb, wc) = sorted((wa, wb, wc))
	need = 2 * wc - wa - wb
	have = n - k - need
	return have >= 0 and have % 3 == 0
for _ in range(Int()):
	(n, k, d1, d2) = value()
	(d3, d4) = (-d1, -d2)
	d1 = [d1, d3]
	d2 = [d2, d4]
	ok = False
	for i in d1:
		for j in d2:
			ok |= check(i, j)
	if ok:
		print('yes')
	else:
		print('no')


import sys
lines = sys.stdin.readlines()
N = int(lines[0].strip())
for i in range(1, 1 + N):
	(n, k, d1, d2) = map(int, lines[i].strip().split(' '))
	if n % 3 != 0:
		print('no')
		continue

	def solve(da, db):
		tmp = k - da - db
		if tmp % 3 != 0:
			return True
		b = tmp // 3
		a = b + da
		c = b + db
		if min(a, b, c) < 0:
			return True
		if n // 3 >= max(a, b, c):
			return False
		else:
			return True
	cannot = True
	if cannot:
		cannot = solve(d1, d2)
	if cannot:
		cannot = solve(d1, -d2)
	if cannot:
		cannot = solve(-d1, d2)
	if cannot:
		cannot = solve(-d1, -d2)
	if cannot:
		print('no')
	else:
		print('yes')


def f(x, y, a, b):
	return x > a or y > b or (a - x) % 3 or (b - y) % 3

def g(x, y, a, b):
	return f(x, y, a, b) and f(x, y, b, a)
for i in range(int(input())):
	(n, u, a, b) = map(int, input().split())
	(v, s, t) = (n - u, a + b, 2 * b - a if b > a else 2 * a - b)
	print('no' if g(s, t, u, v) and g(s + a, s + b, u, v) else 'yes')


def main():
	t = int(input())
	for z in range(t):
		(n, k, d1, d2) = map(int, input().split())
		if n % 3 != 0:
			print('no')
			continue
		f = 0
		for i in [-1, +1]:
			for j in [-1, +1]:
				w = k - i * d1 - j * d2
				if f == 0 and w % 3 == 0 and (n // 3 >= w // 3 >= 0) and (n // 3 >= w // 3 + i * d1 >= 0) and (n // 3 >= w // 3 + j * d2 >= 0):
					print('yes')
					f = 1
		if f == 0:
			print('no')
main()


def check(x, a, b, c):
	n1 = n // 3
	if n % 3 != 0 or abs(n1 - a) + abs(n1 - b) + abs(n1 - c) != n - k or a + b + c != k or (a > n1) or (b > n1) or (c > n1) or (a < 0) or (b < 0) or (c < 0):
		return False
	return True

def fun(d1, d2, k):
	return (k + 2 * d1 + d2) // 3
for t in range(int(input())):
	(n, k, d1, d2) = map(int, input().split())
	flag = False
	x = fun(d1, d2, k)
	(a1, b1, c1) = (x, x - d1, x - d1 - d2)
	flag = flag or check(x, a1, b1, c1)
	x = fun(d1, -d2, k)
	(a2, b2, c2) = (x, x - d1, x - d1 + d2)
	flag = flag or check(x, a2, b2, c2)
	x = fun(-d1, d2, k)
	(a3, b3, c3) = (x, x + d1, x + d1 - d2)
	flag = flag or check(x, a3, b3, c3)
	x = fun(-d1, -d2, k)
	(a4, b4, c4) = (x, x + d1, x + d1 + d2)
	flag = flag or check(x, a4, b4, c4)
	if flag:
		print('yes')
	else:
		print('no')


t = int(input())
for j in range(t):
	inp = [int(n) for n in input().split()]
	n = inp[0]
	k = inp[1]
	d1 = inp[2]
	d2 = inp[3]
	if d2 < d1:
		s = d1
		d1 = d2
		d2 = s
	if k >= 2 * d1 + d2 and (k - 2 * d1 - d2) % 3 == 0 and (n - k >= d1 + 2 * d2) and ((n - k - d1 - 2 * d2) % 3 == 0):
		print('yes')
	elif k >= 2 * d2 + d1 and (k - 2 * d2 - d1) % 3 == 0 and (n - k >= d2 + 2 * d1) and ((n - k - d2 - 2 * d1) % 3 == 0):
		print('yes')
	elif k >= d1 + d2 and (k - d1 - d2) % 3 == 0 and (n - k >= 2 * d2 - d1) and ((n - k - 2 * d2 + d1) % 3 == 0):
		print('yes')
	elif k >= 2 * d2 - d1 and (k - 2 * d2 + d1) % 3 == 0 and (n - k >= d1 + d2) and ((n - k - d1 - d2) % 3 == 0):
		print('yes')
	else:
		print('no')


input = __import__('sys').stdin.readline
for _ in range(int(input())):
	(n, k, d1, d2) = map(int, input().split())
	lis = [[2 * d1 + d2, 2 * d2 + d1], [2 * d2 + d1, 2 * d1 + d2], [2 * max(d1, d2) - min(d1, d2), d1 + d2], [d1 + d2, 2 * max(d1, d2) - min(d1, d2)]]
	flag = 1
	for i in lis:
		if i[0] <= k and i[0] % 3 == k % 3 and (n - k - i[1] >= 0) and ((n - k - i[1]) % 3 == 0):
			print('yes')
			flag = 0
			break
	if flag:
		print('no')


import sys
import operator
input = sys.stdin.readline

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

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

def solve():
	(n, k, d1, d2) = read_ints()
	if n % 3 != 0:
		return 'no'

	def check(n, k, d1, d2, op1, op2):
		if (d1 - d2 - k) % 3 != 0:
			return False
		w1 = d1 - (d1 - d2 - k) // 3
		w2 = -(d1 - d2 - k) // 3
		w3 = -(d1 - d2 - k) // 3 - d2
		if w1 >= 0 and w2 >= 0 and (w3 >= 0) and (n // 3 - w1 >= 0) and (n // 3 - w2 >= 0) and (n // 3 - w3 >= 0) and op1(w1, w2) and op2(w2, w3):
			return True
		return False
	if check(n, k, d1, d2, operator.ge, operator.ge):
		return 'yes'
	if check(n, k, d1, -d2, operator.ge, operator.lt):
		return 'yes'
	if check(n, k, -d1, d2, operator.lt, operator.ge):
		return 'yes'
	if check(n, k, -d1, -d2, operator.lt, operator.lt):
		return 'yes'
	return 'no'
T = read_int()
for _ in range(T):
	print(solve())


def doall():
	t = int(input())

	def solve(n, k, d1, d2):
		if n % 3 == 0:
			r = n - k
			a = [[0, d1, d1 + d2], [0, d1, d1 - d2], [0, -d1, -d1 + d2], [0, -d1, -d1 - d2]]
			for now in a:
				mn = min(now)
				sumn = sum(now)
				sumb = sumn - 3 * min(now)
				if k < sumb or (k - sumb) % 3 != 0:
					continue
				w = max(now)
				tmp = 3 * w - sumn
				if tmp <= r and (r - tmp) % 3 == 0:
					return True
		return False
	ans = []
	for i in range(t):
		(n, k, d1, d2) = list(map(int, input().split()))
		if solve(n, k, d1, d2):
			ans.append('yes')
		else:
			ans.append('no')
	print('\n'.join(ans))
doall()


def check(n, k, d1, d2):
	if (k - d1 - d2) % 3 != 0:
		return False
	y = (k - d1 - d2) // 3
	x = y + d1
	z = y + d2
	t = n // 3
	if x < 0 or y < 0 or z < 0:
		return False
	if x > t or y > t or z > t:
		return False
	return True
t = int(input())
for _ in range(t):
	(n, k, d1, d2) = map(int, input().split())
	if n % 3 != 0:
		print('no')
		continue
	if check(n, k, d1, d2):
		print('yes')
		continue
	if check(n, k, -d1, d2):
		print('yes')
		continue
	if check(n, k, d1, -d2):
		print('yes')
		continue
	if check(n, k, -d1, -d2):
		print('yes')
		continue
	print('no')


def f1(d1, d2, n, k):
	a1 = 2 * d1 + d2 + k
	a2 = -d1 + d2 + k
	a3 = -d1 - 2 * d2 + k
	if a1 < 0 or a2 < 0 or a3 < 0 or a1 % 3 or a2 % 3 or a2 % 3:
		return False
	else:
		a1 //= 3
		a2 //= 3
		a3 //= 3
		(a1, a2, a3) = tuple(sorted([a1, a2, a3])[::-1])
		if a2 - a3 + 2 * (a1 - a2) > n - k:
			return False
		else:
			return True

def f2(d1, d2, n, k):
	a1 = -2 * d1 + d2 + k
	a2 = d1 + d2 + k
	a3 = d1 - 2 * d2 + k
	if a1 < 0 or a2 < 0 or a3 < 0 or a1 % 3 or a2 % 3 or a2 % 3:
		return False
	else:
		a1 //= 3
		a2 //= 3
		a3 //= 3
		(a1, a2, a3) = tuple(sorted([a1, a2, a3])[::-1])
		if a2 - a3 + 2 * (a1 - a2) > n - k:
			return False
		else:
			return True

def f3(d1, d2, n, k):
	a1 = 2 * d1 - d2 + k
	a2 = -d1 - d2 + k
	a3 = -d1 + 2 * d2 + k
	if a1 < 0 or a2 < 0 or a3 < 0 or a1 % 3 or a2 % 3 or a2 % 3:
		return False
	else:
		a1 //= 3
		a2 //= 3
		a3 //= 3
		(a1, a2, a3) = tuple(sorted([a1, a2, a3])[::-1])
		if a2 - a3 + 2 * (a1 - a2) > n - k:
			return False
		else:
			return True

def f4(d1, d2, n, k):
	a1 = -2 * d1 - d2 + k
	a2 = d1 - d2 + k
	a3 = d1 + 2 * d2 + k
	if a1 < 0 or a2 < 0 or a3 < 0 or a1 % 3 or a2 % 3 or a2 % 3:
		return False
	else:
		a1 //= 3
		a2 //= 3
		a3 //= 3
		(a1, a2, a3) = tuple(sorted([a1, a2, a3])[::-1])
		if a2 - a3 + 2 * (a1 - a2) > n - k:
			return False
		else:
			return True
a = []
z = int(input())
for i in range(z):
	(n, k, d1, d2) = map(int, input().split())
	v1 = f1(d1, d2, n, k)
	v2 = f2(d1, d2, n, k)
	v3 = f3(d1, d2, n, k)
	v4 = f4(d1, d2, n, k)
	if (v1 or v2 or v3 or v4) and n % 3 == 0:
		a.append('yes')
	else:
		a.append('no')
print(*a, sep='\n')