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 d1 and that of between second and third team will be d2.
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.
The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105).
Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.
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).
5 3 0 0 0 3 3 0 0 6 4 1 0 6 3 3 0 3 3 3 2
yes yes yes no no
Sample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 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 d1 = 0 and d2 = 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 d1 = 1, d2 = 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).
//AC代码
/*
题意:有3支球队进行n场比赛,但是其中你有k比赛错过了,你的朋友知道k场比赛的结果但是你的朋友只告诉你这k场比赛
中每一场第一只球队和第二只球队比分绝对值d1和第二只球队和第三只球队比分绝对值d2,然后你不想任何球队胜出,所以问你是否存在这样的比分使得
没有球队胜出
*/
#include<iostream>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<map>
#include<cstdlib>
#include<cmath>
const double eps=1e-8;
const double PI=3.1415926;
const int Max=1001;
#define zero(x) (((x)>0?(x):-(x))<eps)
using namespace std;
int sign(double x)
{
return (x>eps)-(x<-eps);
}
typedef struct Node
{
double x;
double y;
}point;
point list[Max],stack[Max];
int top;
int n;
double xmult(point p0,point p1,point p2)
{
return(p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
double Distance(point p1,point p2)// 返回两点之间欧氏距离
{
return( sqrt( (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y) ) );
}
bool cmp(point p1,point p2)
{
double temp;
temp=xmult(list[0],p1,p2);
if(temp>0)
return true;
if(temp==0&&(Distance(list[0],p1)<Distance(list[0],p2)))
return true;
return false;
}
void convex_hull()//凸包模板
{
int i;
for(i=1;i<n;i++)
{
point temp;
if((list[i].y<list[0].y)||(list[i].y==list[0].y&&list[i].x<list[0].x))
swap(list[0],list[i]);
}
sort(list+1,list+n,cmp);
top=1;
stack[0]=list[0];
stack[1]=list[1];
for(i=2;i<n;i++)
{
while(top>=1&&xmult(stack[top-1],stack[top],list[i])<=0)
top--;
top++;
stack[top]=list[i];
}
}
int main()
{
long long t,n,k,u,v,x,y,z;
cin>>t;
while(t--)
{
cin>>n>>k>>u>>v;
int flag=0;
if((k-u-2*v)%3==0&&k-u-2*v>=0)
{
z=(k-u-2*v)/3;
y=z+v;
x=y+u;
//cout<<x<<" "<<y<<" "<<z<<endl;
long long res=0;
res=max(res,x);
res=max(res,y);
res=max(res,z);
if(x+y+z==k)
{
long long temp=res-x+res-y+res-z;
temp=n-k-temp;
if(temp>=0&&temp%3==0)
flag=1;
}
}
if((k-u-v)%3==0&&k-u-v>=0)
{
y=(k-u-v)/3;
x=y+u;
z=y+v;
long long res=0;
res=max(res,x);
res=max(res,y);
res=max(res,z);
if(x+y+z==k)
{
long long temp=res-x+res-y+res-z;
temp=n-k-temp;
if(temp>=0&&temp%3==0)
flag=1;
}
}
if((k-u*2-v)%3==0&&k-u*2-v>=0)
{
x=(k-2*u-v)/3;
y=x+u;
z=y+v;
long long res=0;
res=max(res,x);
res=max(res,y);
res=max(res,z);
if(x+y+z==k)
{
long long temp=res-x+res-y+res-z;
temp=n-k-temp;
if(temp>=0&&temp%3==0)
flag=1;
}
}
if((k+u+v)%3==0&&k+u+v>=0)
{
y=(k+u+v)/3;
x=y-u;
z=y-v;
long long res=0;
res=max(res,x);
res=max(res,y);
res=max(res,z);
if(x+y+z==k&&x>=0&&y>=0&&z>=0)
{
long long temp=res-x+res-y+res-z;
temp=n-k-temp;
if(temp>=0&&temp%3==0)
flag=1;
}
}
if(flag)
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
}