#include <cstdio>
#include <iostream>

using namespace std;

int nTest;
long long n, k, d1, d2;

bool isOK(long long a, long long b, long long c) {
    if (a < 0) {
        b -= a; c -= a; a -= a;
    }
    if (b < 0) {
        c -= b; a -= b; b -= b;
    }
    if (c < 0) {
        a -= c; b -= c; c -= c;
    }
    if (a+b+c > k) return 0;
    long long m = max(a, max(b, c));
    if (n-k < m-a + m-b + m-c) return 0;
    if (((n-k) - (m-a + m-b + m-c)) % 3 != 0) return 0;
    return 1;
}

int main() {
    // freopen("C.txt", "r", stdin);

    ios_base :: sync_with_stdio(0);
    for (cin >> nTest; nTest; nTest--) {

        cin >> n >> k >> d1 >> d2;
        bool ok = 0;
        ok |= isOK(0, d1, d1+d2);
        ok |= isOK(0, d1, d1-d2);
        ok |= isOK(d1, 0, d2);
        ok |= isOK(d2+d1, d2, 0);
        ok |= isOK(d2-d1, d2, 0);
        cout << (ok ? "yes" : "no") << "\n";
    }

    return 0;
}


#include <cstdio>
#include <iostream>

using namespace std;

int nTest;
long long n, k, d1, d2;

bool isOK(long long a, long long b, long long c) {
    if (a < 0) {
        b -= a; c -= a; a -= a;
    }
    if (b < 0) {
        c -= b; a -= b; b -= b;
    }
    if (c < 0) {
        a -= c; b -= c; c -= c;
    }
    if (a+b+c > k) return 0;
    long long m = max(a, max(b, c));
    if (n-k < m-a + m-b + m-c) return 0;
    if (((n-k) - (m-a + m-b + m-c)) % 3 != 0) return 0;
    return 1;
}

int main() {
    // freopen("C.txt", "r", stdin);

    ios_base :: sync_with_stdio(0);
    for (cin >> nTest; nTest; nTest--) {

        cin >> n >> k >> d1 >> d2;
        bool ok = 0;
        ok |= isOK(0, d1, d1+d2);
        ok |= isOK(0, d1, d1-d2);
        ok |= isOK(d1, 0, d2);
        ok |= isOK(-d1, 0, -d2);
        ok |= isOK(d2+d1, d2, 0);
        ok |= isOK(d2-d1, d2, 0);
        cout << (ok ? "yes" : "no") << "\n";
    }

    return 0;
}


#include <cstdio>
#include <iostream>

using namespace std;

int nTest;
long long n, k, d1, d2;

bool isOK(long long a, long long b, long long c) {
    if (a < 0) {
        b -= a; c -= a; a -= a;
    }
    if (b < 0) {
        c -= b; a -= b; b -= b;
    }
    if (c < 0) {
        a -= c; b -= c; c -= c;
    }
    if (a+b+c > k) return 0;
    if ((k - (a+b+c)) % 3 != 0) return 0;
    long long m = max(a, max(b, c));
    if (n-k < m-a + m-b + m-c) return 0;
    if (((n-k) - (m-a + m-b + m-c)) % 3 != 0) return 0;
    return 1;
}

int main() {
    // freopen("C.txt", "r", stdin);

    ios_base :: sync_with_stdio(0);
    for (cin >> nTest; nTest; nTest--) {

        cin >> n >> k >> d1 >> d2;
        bool ok = 0;
        ok |= isOK(0, d1, d1+d2);
        ok |= isOK(0, d1, d1-d2);
        ok |= isOK(d1, 0, d2);
        ok |= isOK(-d1, 0, -d2);
        ok |= isOK(d2+d1, d2, 0);
        ok |= isOK(d2-d1, d2, 0);
        cout << (ok ? "yes" : "no") << "\n";
    }

    return 0;
}


#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;

int nTest;

int main() {
    // freopen("C.txt", "r", stdin);

    ios_base :: sync_with_stdio(0);
    for (cin >> nTest; nTest; nTest--) {
        long long n, k, d1, d2;
        cin >> n >> k >> d1 >> d2;
        bool ok = 0;
        if (k >= 2*d1 + d2 && (n-k) >= (d1+2*d2) && ((n-k) - (d1+2*d2)) % 3 == 0) ok = 1;
        if (k >= max(d1, d2) + abs(d1-d2) && (n-k) >= (d1+d2) && ((n-k) - (d1+d2)) % 3 == 0) ok = 1;
        if (k >= d1 + 2*d2 && (n-k) >= (2*d1+d2) && ((n-k) - (2*d1+d2)) % 3 == 0) ok = 1;

        cout << (ok ? "yes" : "no") << "\n";
    }

    return 0;
}


// C_ac.cpp : �������̨Ӧ�ó������ڵ㡣
//
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long LL;
int sovleFaster(LL n, LL k, LL d1, LL d2){
	if(n % 3 != 0){
		return false;
	}
	for(int i=-1;i<=1;i++){
		for(int j=-1;j<=1;j++){
			if(i == 0 || j == 0){
				continue;
			}
			LL D1 = i * d1;
			LL D2 = j * d2;
			LL x2 = (k - D1 + D2) / 3;
			if((k-D1+D2) % 3 != 0){
				continue;
			}
			if(x2 >= 0 && x2 <= k){
				LL x1 = x2 + D1;
				LL x3 = x2 - D2;
				if(x1>=0 && x1 <= k && x3>= 0 && x3 <= k){
					if(x1<=n/3 && x2<=n/3 && x3<=n/3){
						return true;
					}
				}
			}
		}
	}
	return false;
}

int main(){
	int T;
	while(~scanf("%d",&T)){
		while(T--){
			LL n,k,d1,d2;
			cin>>n>>k>>d1>>d2;
			//scanf("%lld %lld %lld %lld",&n,&k,&d1,&d2);
			bool ans = sovleFaster(n,k,d1,d2);
			if(ans){
				printf("yes\n");
			}else{
				printf("no\n");
			}
		}
	}
	return 0;
}


// C.cpp : �������̨Ӧ�ó������ڵ㡣
//
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int t;
	int d,k,s1,s2;
	int dir[2] = {-1,1};
	while(~scanf("%d",&t)){
		while(t--){
			scanf("%d %d %d %d",&d,&k,&s1,&s2);
			int u = d - k;
			int a,b,c;
			bool flag = true;
			for(int i=0;i<=k && flag;i++){
				a = i;
				for(int j=0;j<2 && flag;j++){
					b = a + dir[j] * s1;
					if(b < 0) continue;
					for(int v=0;v<2 && flag;v++){
						c = b + dir[v] * s2;
						if(c < 0 || a + b + c > k) continue;
						int mmax = max(a,max(b,c));
						int cnt = mmax - a + mmax - b + mmax - c;
						if((u-cnt >=0 && (u-cnt)%3 == 0) && a + b + c == k){
							cout<<a<<" "<<b<<" "<<c<<endl;
							flag = false;
						}
					}
				}
			}
			if(!flag){
				printf("yes\n");
			}
			else{
				printf("no\n");
			}
		}
	}
	return 0;
}


// C.cpp : �������̨Ӧ�ó������ڵ㡣
//
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int t;
	long long d,k,s1,s2;
	int dir[2] = {-1,1};
	while(~scanf("%d",&t)){
		while(t--){
			scanf("%d %d %d %d",&d,&k,&s1,&s2);
			long long  u = d - k;
			long long a,b,c;
			bool flag = true;
			for(long long i=0;i<=k && flag;i++){
				a = i;
				for(long long j=0;j<2 && flag;j++){
					b = a + dir[j] * s1;
					if(b < 0) continue;
					for(long long  v=0;v<2 && flag;v++){
						c = b + dir[v] * s2;
						if(c < 0 || a + b + c > k) continue;
						long long  mmax = max(a,max(b,c));
						long long cnt = mmax - a + mmax - b + mmax - c;
						if((u-cnt >=0 && (u-cnt)%3 == 0) && a + b + c == k){
							flag = false;
						}
					}
				}
			}
			if(!flag){
				printf("yes\n");
			}
			else{
				printf("no\n");
			}
		}
	}
	return 0;
}


// C.cpp : �������̨Ӧ�ó������ڵ㡣
//
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int t;
	int d,k,s1,s2;
	int dir[2] = {-1,1};
	while(~scanf("%d",&t)){
		while(t--){
			scanf("%d %d %d %d",&d,&k,&s1,&s2);
			int u = d - k;
			int a,b,c;
			bool flag = true;
			for(int i=0;i<=k && flag;i++){
				a = i;
				for(int j=0;j<2 && flag;j++){
					b = a + dir[j] * s1;
					if(b < 0) continue;
					for(int v=0;v<2 && flag;v++){
						c = b + dir[v] * s2;
						if(c < 0 || a + b + c > k) continue;
						int mmax = max(a,max(b,c));
						int cnt = mmax - a + mmax - b + mmax - c;
						if((u-cnt >=0 && (u-cnt)%3 == 0) && a + b + c == k){
							flag = false;
						}
					}
				}
			}
			if(!flag){
				printf("yes\n");
			}
			else{
				printf("no\n");
			}
		}
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <assert.h>
#include <cstdio>

using namespace std;

typedef long long ll;
typedef double db;
typedef string str;

#define INF 1e+9
#define EPS 1e-9
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define pii pair<int,int>
#define pdd pair<db,db>
#define X first
#define Y second
#define sz(a) ( (int) a.size() )
#define len(a) ( (int) a.length() )
#define ALL(a) a.begin(),a.end()

#ifdef _DEBUG
	const int maxn = 10;
#else
	const int maxn = 2e+5;
#endif

long long n, k, d1, d2;

bool fun (long long w1, long long w2, long long w3){
	if (w1 < 0 || w2 < 0 || w3 < 0) return false;
	vector<long long> b;
	b.pb(w1);
	b.pb(w2);
	b.pb(w3);
	sort(ALL(b));
	long long d = n - k - (b[2] - b[1]) - (b[2] - b[0]);
	if (d < 0) return false;
	if (d%3) return false;
	return true;
}

bool check1(){
	long long w1 = k - 2 * d1 - d2;
	if (w1 < 0) return false;
	if (w1 % 3) return false;
	w1 /= 3;
	long long w2 = d1 + w1;
	long long w3 = d2 + w2;
	return fun(w1,w2,w3);
}

bool check2(){
	long long w1 = k - 2 * d1 + d2;
	if (w1 < 0) return false;
	if (w1 % 3) return false;
	w1 /= 3;
	long long w2 = d1 + w1;
	long long w3 = w2 - d2;
	if (w2 < 0 || w3 < 0) return false;
	return fun(w1,w2,w3);
}

bool check3(){
	long long w1 = k + 2 * d1 + d2;
	if (w1 < 0) return false;
	if (w1 % 3) return false;
	w1 /= 3;
	long long w2 = w1 - d1;
	long long w3 = w2 - d2;
	if (w2 < 0 || w3 < 0) return false;
	return fun(w1,w2,w3);
}

bool check4(){
	long long w1 = k + 2 * d1 - d2;
	if (w1 < 0) return false;
	if (w1 % 3) return false;
	w1 /= 3;
	long long w2 = w1 - d1;
	long long w3 = w2 + d2;
	if (w2 < 0 || w3 < 0) return false;
	return fun(w1,w2,w3);
}

bool solve(){
	int ch = n - k - d1 -d2;
	if (ch < 0) return false;
	if (check1()) return true;
	if (check2()) return true;
	if (check3()) return true;
	if (check4()) return true;
	return false;
}

int main(){
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);*/
#endif
	int t;
	scanf("%d", &t);
	while(t--){
		scanf("%I64d%I64d%I64d%I64d", &n,&k, &d1, &d2);
		long long delta = n - k;
		if (n%3){
			printf("no\n");
			continue;
		}
		if (solve()){
			printf("yes\n");
			continue;
		}
		printf("no\n");
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <assert.h>
#include <cstdio>

using namespace std;

typedef long long ll;
typedef double db;
typedef string str;

#define INF 1e+9
#define EPS 1e-9
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define pii pair<int,int>
#define pdd pair<db,db>
#define X first
#define Y second
#define sz(a) ( (int) a.size() )
#define len(a) ( (int) a.length() )
#define ALL(a) a.begin(),a.end()

#ifdef _DEBUG
	const int maxn = 10;
#else
	const int maxn = 2e+5;
#endif

long long n, k, d1, d2;

bool fun (long long w1, long long w2, long long w3){
	if (w1 < 0 || w2 < 0 || w3 < 0) return false;
	vector<long long> b;
	b.pb(w1);
	b.pb(w2);
	b.pb(w3);
	sort(ALL(b));
	long long d = n - k - (b[2] - b[1]) - (b[2] - b[0]);
	if (d < 0) return false;
	if (d%3) return false;
	return true;
}

bool check1(){
	long long w1 = k - 2 * d1 - d2;
	if (w1 % 3) return false;
	w1 /= 3;
	long long w2 = d1 + w1;
	long long w3 = d2 + w2;
	return fun(w1,w2,w3);
}

bool check2(){
	long long w1 = k - 2 * d1 + d2;
	if (w1 % 3) return false;
	w1 /= 3;
	long long w2 = d1 + w1;
	long long w3 = w2 - d2;
	if (w2 < 0 || w3 < 0) return false;
	return fun(w1,w2,w3);
}

bool check3(){
	long long w1 = k + 2 * d1 + d2;
	if (w1 % 3) return false;
	w1 /= 3;
	long long w2 = w1 - d1;
	long long w3 = w2 - d2;
	return fun(w1,w2,w3);
}

bool check4(){
	long long w1 = k + 2 * d1 - d2;
	if (w1 % 3) return false;
	w1 /= 3;
	long long w2 = w1 - d1;
	long long w3 = w2 + d2;
	return fun(w1,w2,w3);
}

bool solve(){
	if (check1()) return true;
	if (check2()) return true;
	if (check3()) return true;
	if (check4()) return true;
	return false;
}

int main(){
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);*/
#endif
	int t;
	scanf("%d", &t);
	while(t--){
		scanf("%I64d%I64d%I64d%I64d", &n,&k, &d1, &d2);
		long long delta = n - k;
		if (n%3){
			printf("no\n");
			continue;
		}
		if (solve()){
			printf("yes\n");
			continue;
		}
		printf("no\n");
	}
	return 0;
}


#pragma comment(linker,"/STACK:67108864")
#include <iostream>
#include <iomanip>
#include <fstream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <sstream>
#include <bitset>
#include <iterator>
#include <list>

#define FR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,c,n) for(int (i)=(c);(i)<(n);(i)++)
#define REP(it,v,cont) for((cont)::iterator (it)=(v).begin();(it)!=(v).end();++(it))
#define CLR(a,c) memset((a),(c),sizeof (a))
#define ALL(v) (v).begin(),(v).end()
#define VCPRINT(v) for(int iii = 0;iii < (v).size();iii++) cout<<(v)[iii]<<" ";cout<<endl;
#define SETPRINT(v,cont) for((cont)::iterator iiit = (v).begin();iiit != (v).end();iiit++) cout<<*iiit<<" ";cout<<endl;

bool ascending (int i,int j) { return (i<j); }
bool descending (int i,int j) { return (i>j); }

typedef long long ll;
typedef unsigned long long ull;
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define PULI pair<unsigned long long,int>
#define PIL pair<int,long long>
#define PSI pair<string,int>
#define PSS pair<string,string>
#define PDD pair<double,double>
#define PIB pair<int,bool>
typedef long double ld;

using namespace std;

int A[1000*100+100];

int main()
{
	int t;cin>>t;
	while(t--)
	{
		int n,k,D1,D2;
		cin>>n>>k>>D1>>D2;

		bool flag = false;

		int a1,a2,a3;
		for(int i = 0;i < 4;i++)
		{
			int d1 = D1 * (i&1 ? 1 : -1);
			int d2 = D2 * (i&2 ? 1 : -1);
			if((2*d1+d2+k)%3==0)
			{
				a1 = (2*d1+d2+k)/3;
				a2 = a1-d1;
				a3 = k-a1-a2;
				if(a1>=0 && a2>=0 && a3>=0)
				{
					int A[] = {a1,a2,a3};
					sort(A,A+3);
					int tmp = n-k;
					tmp -= A[2]-A[1];
					tmp -= A[2]-A[0];
					if(tmp>=0 && tmp%3==0)
					{
						flag = true;
					}
				}
			}
		}

		if(flag) cout<<"yes"<<endl;
		else cout<<"no"<<endl;

	}
}


#pragma comment(linker,"/STACK:67108864")
#include <iostream>
#include <iomanip>
#include <fstream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <sstream>
#include <bitset>
#include <iterator>
#include <list>

#define FR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,c,n) for(int (i)=(c);(i)<(n);(i)++)
#define REP(it,v,cont) for((cont)::iterator (it)=(v).begin();(it)!=(v).end();++(it))
#define CLR(a,c) memset((a),(c),sizeof (a))
#define ALL(v) (v).begin(),(v).end()
#define VCPRINT(v) for(int iii = 0;iii < (v).size();iii++) cout<<(v)[iii]<<" ";cout<<endl;
#define SETPRINT(v,cont) for((cont)::iterator iiit = (v).begin();iiit != (v).end();iiit++) cout<<*iiit<<" ";cout<<endl;

bool ascending (int i,int j) { return (i<j); }
bool descending (int i,int j) { return (i>j); }

typedef long long ll;
typedef unsigned long long ull;
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define PULI pair<unsigned long long,int>
#define PIL pair<int,long long>
#define PSI pair<string,int>
#define PSS pair<string,string>
#define PDD pair<double,double>
#define PIB pair<int,bool>
typedef long double ld;

using namespace std;

int main()
{
	int t;cin>>t;
	while(t--)
	{
		ll n,k,D1,D2;
		cin>>n>>k>>D1>>D2;

		bool flag = false;

		ll a1,a2,a3;
		for(ll i = 0;i < 4;i++)
		{
			ll d1 = D1 * (i&1 ? 1 : -1);
			ll d2 = D2 * (i&2 ? 1 : -1);
			if((2*d1+d2+k)%3==0)
			{
				a1 = (2*d1+d2+k)/3;
				a2 = a1-d1;
				a3 = k-a1-a2;
				if(a1>=0 && a2>=0 && a3>=0)
				{
					ll A[] = {a1,a2,a3};
					sort(A,A+3);
					ll tmp = n-k;
					tmp -= A[2]-A[1];
					tmp -= A[2]-A[0];
					if(tmp>=0 && tmp%3==0)
					{
						flag = true;
					}
				}
			}
		}

		if(flag) cout<<"yes"<<endl;
		else cout<<"no"<<endl;

	}
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#define Inf 0x3f3f3f3f
#define Maxn 10000
#define LL long long
using namespace std;
int main()
{
	LL a,b,c,n,k,d1,d2;
	int t;
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	scanf("%d",&t);
	while(t--)
	{
		cin>>n>>k>>d1>>d2;
		a=(2*d1+d2+k)/3;
		b=a-d1;
		c=b-d2;
		if(a>=0&&b>=0&&c>=0)
		{
			a=a;b=b;c=c;
		}
		else
		{
			a=(-2*d1+d2+k)/3;
			b=a+d1;
			c=b-d2;
			if(a>=0&&b>=0&&c>=0)
			{
				a=a;b=b;c=c;
			}
			else
			{
				a=(2*d1+k-d2)/3;
				b=a-d1;
				c=b+d2;
				if(a>=0&&b>=0&&c>=0)
				{
					a=a;b=b;c=c;
				}
				else
				{
					a=(k-d1*2-d2)/3;
					b=a+d1;
					c=b+d2;
				}
			}
		}
		//cout<<a<<" "<<b<<c<<endl;
		if(n%3)
			puts("no");
		else
		{
			if(a>n/3||b>n/3||c>n/3)
				puts("no");
			else if(n-k>=a-n/3+b-n/3+c-n/3)
				puts("yes");
			else
				puts("no");
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#define Inf 0x3f3f3f3f
#define Maxn 10000
#define LL long long
using namespace std;
bool check(int a,int b,int c,int n)
{
	if(a>=0&&b>=0&&c>=0&&a<=n/3&&b<=n/3&&c<=n/3)
		return true;
	return false;
}
int main()
{
	LL a,b,c,n,k,d1,d2;
	int t;
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	scanf("%d",&t);
	while(t--)
	{
		cin>>n>>k>>d1>>d2;
		if(n%3)
		{
			puts("no");
			continue;
		}
		a=(2*d1+d2+k)/3;
		b=a-d1;
		c=b-d2;
		if(check(a,b,c,n))
		{
			puts("yes");
			continue;
		}
		else
		{
			a=(-2*d1+d2+k)/3;
			b=a+d1;
			c=b-d2;
			if(check(a,b,c,n))
			{
				puts("yes");
				continue;
			}
			else
			{
				a=(2*d1+k-d2)/3;
				b=a-d1;
				c=b+d2;
				if(check(a,b,c,n))
				{
					puts("yes");
					continue;
				}
				else
				{
					a=(k-d1*2-d2)/3;
					b=a+d1;
					c=b+d2;
					if(check(a,b,c,n))
					{
						puts("yes");
						continue;
					}
				}
			}
		}
		puts("no");
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#define Inf 0x3f3f3f3f
#define Maxn 10000
#define LL long long
using namespace std;
bool check(int a,int b,int c,int n)
{
	if(a>=0&&b>=0&&c>=0&&a<=n/3&&b<=n/3&&c<=n/3)
		return true;
	return false;
}
int main()
{
	LL a,b,c,n,k,d1,d2;
	int t;
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	scanf("%d",&t);
	while(t--)
	{
		cin>>n>>k>>d1>>d2;
		if(n%3)
		{
			puts("no");
			continue;
		}
		if((2*d1+d2+k)%3==0)
		{
			a=(2*d1+d2+k)/3;
			b=a-d1;
			c=b-d2;
			if(check(a,b,c,n))
			{
				puts("yes");
				continue;
			}
		}
		else
		{
			if((-2*d1+d2+k)%3==0)
			{
				a=(-2*d1+d2+k)/3;
				b=a+d1;
				c=b-d2;
				if(check(a,b,c,n))
				{
					puts("yes");
					continue;
				}
			}
			else
			{
				if((2*d1+k-d2)%3==0)
				{
					a=(2*d1+k-d2)/3;
					b=a-d1;
					c=b+d2;
					if(check(a,b,c,n))
					{
						puts("yes");
						continue;
					}
				}
				else
				{
					if((k-d1*2-d2)%3==0)
					{
						a=(k-d1*2-d2)/3;
						b=a+d1;
						c=b+d2;
						if(check(a,b,c,n))
						{
							puts("yes");
							continue;
						}
					}
				}
			}
		}
		puts("no");
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#define Inf 0x3f3f3f3f
#define Maxn 10000
#define LL long long
using namespace std;
bool check(int a,int b,int c,int n)
{
	if(a>=0&&b>=0&&c>=0&&a<=n/3&&b<=n/3&&c<=n/3)
		return true;
	return false;
}
int main()
{
	LL a,b,c,n,k,d1,d2;
	int t;
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	scanf("%d",&t);
	while(t--)
	{
		cin>>n>>k>>d1>>d2;
		if(n%3)
		{
			puts("no");
			continue;
		}
		if((2*d1+d2+k)%3==0)
		{
			a=(2*d1+d2+k)/3;
			b=a-d1;
			c=b-d2;
			if(check(a,b,c,n))
			{
				puts("yes");
				continue;
			}
		}
		if((-2*d1+d2+k)%3==0)
		{
			a=(-2*d1+d2+k)/3;
			b=a+d1;
			c=b-d2;
			if(check(a,b,c,n))
			{
				puts("yes");
				continue;
			}
		}
		if((2*d1+k-d2)%3==0)
		{
			a=(2*d1+k-d2)/3;
			b=a-d1;
			c=b+d2;
			if(check(a,b,c,n))
			{
				puts("yes");
				continue;
			}
		}
		if((k-d1*2-d2)%3==0)
		{
			a=(k-d1*2-d2)/3;
			b=a+d1;
			c=b+d2;
			if(check(a,b,c,n))
			{
				puts("yes");
				continue;
			}
		}
		puts("no");
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#define Inf 0x3f3f3f3f
#define Maxn 10000
#define LL long long
using namespace std;
bool check(int a,int b,int c,int n)
{
	if(a>=0&&b>=0&&c>=0&&a<=n/3&&b<=n/3&&c<=n/3)
		return true;
	return false;
}
int main()
{
	LL a,b,c,n,k,d1,d2,tmp;
	int t;
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	scanf("%d",&t);
	while(t--)
	{
		cin>>n>>k>>d1>>d2;
		if(n%3)
		{
			puts("no");
			continue;
		}
		tmp=k-d1+d2;
		if(tmp%3==0)
		{
			b=tmp/3;
			a=d1+b;
			c=b-d2;
			if(check(a,b,c,n))
			{
				puts("yes");
				continue;
			}
		}
		tmp=k+d1+d2;
		if(tmp%3==0)
		{
			b=tmp/3;
			a=b-d1;
			c=b-d2;
			if(check(a,b,c,n))
			{
				puts("yes");
				continue;
			}
		}
		tmp=k-d1-d2;
		if(tmp%3==0)
		{
			b=tmp/3;
			a=d1+b;
			c=b+d2;
			if(check(a,b,c,n))
			{
				puts("yes");
				continue;
			}
		}
		tmp=k+d1-d2;
		if(tmp%3==0)
		{
			b=tmp/3;
			a=b-d1;
			c=b+d2;
			if(check(a,b,c,n))
			{
				puts("yes");
				continue;
			}
		}
		puts("no");
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#define Inf 0x3f3f3f3f
#define Maxn 10000
#define LL long long
using namespace std;
bool check(LL a,LL b,LL c,LL n)
{
	if(a>=0&&b>=0&&c>=0&&a<=n/3&&b<=n/3&&c<=n/3)
		return true;
	return false;
}
int main()
{
	LL a,b,c,n,k,d1,d2,tmp;
	int t;
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	scanf("%d",&t);
	while(t--)
	{
		cin>>n>>k>>d1>>d2;
		if(n%3)
		{
			puts("no");
			continue;
		}
		tmp=k-d1+d2;
		if(tmp%3==0)
		{
			b=tmp/3;
			a=d1+b;
			c=b-d2;
			if(check(a,b,c,n))
			{
				puts("yes");
				continue;
			}
		}
		tmp=k+d1+d2;
		if(tmp%3==0)
		{
			b=tmp/3;
			a=b-d1;
			c=b-d2;
			if(check(a,b,c,n))
			{
				puts("yes");
				continue;
			}
		}
		tmp=k-d1-d2;
		if(tmp%3==0)
		{
			b=tmp/3;
			a=d1+b;
			c=b+d2;
			if(check(a,b,c,n))
			{
				puts("yes");
				continue;
			}
		}
		tmp=k+d1-d2;
		if(tmp%3==0)
		{
			b=tmp/3;
			a=b-d1;
			c=b+d2;
			if(check(a,b,c,n))
			{
				puts("yes");
				continue;
			}
		}
		puts("no");
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#define Inf 0x3f3f3f3f
#define Maxn 10000
#define LL long long
using namespace std;
int main()
{
	LL a,b,c,n,k,d1,d2;
	int t;
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	scanf("%d",&t);
	while(t--)
	{
		cin>>n>>k>>d1>>d2;
		a=(2*d1+d2+k)/3;
		b=a-d1;
		c=b-d2;
		if(a>=0&&b>=0&&c>=0)
		{
			a=a;b=b;c=c;
		}
		else
		{
			a=(-2*d1+d2+k)/3;
			b=a+d1;
			c=b-d2;
			if(a>=0&&b>=0&&c>=0)
			{
				a=a;b=b;c=c;
			}
			else
			{
				a=(2*d1+k-d2)/3;
				b=a-d1;
				c=b+d2;
				if(a>=0&&b>=0&&c>=0)
				{
					a=a;b=b;c=c;
				}
				else
				{
					a=(k-d1*2-d2)/3;
					b=a+d1;
					c=b+d2;
				}
			}
		}
		//cout<<a<<" "<<b<<c<<endl;
		if(n%3)
			puts("no");
		else
		{
			if(a>n/3||b>n/3||c>n/3)
				puts("no");
			else if(n-k>=n/3-a+n/3-b+n/3-c)
				puts("yes");
			else
				puts("no");
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#define Inf 0x3f3f3f3f
#define Maxn 10000
#define LL long long
using namespace std;
int main()
{
	LL a,b,c,n,k,d1,d2;
	int t;
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	scanf("%d",&t);
	while(t--)
	{
		cin>>n>>k>>d1>>d2;
		a=(2*d1+d2+k)/3;
		b=a-d1;
		c=b-d2;
		if(a>=0&&b>=0&&c>=0)
		{
			a=a;b=b;c=c;
		}
		else
		{
			a=(-2*d1+d2+k)/3;
			b=a+d1;
			c=b-d2;
			if(a>=0&&b>=0&&c>=0)
			{
				a=a;b=b;c=c;
			}
			else
			{
				a=(2*d1+k-d2)/3;
				b=a-d1;
				c=b+d2;
				if(a>=0&&b>=0&&c>=0)
				{
					a=a;b=b;c=c;
				}
				else
				{
					a=(k-d1*2-d2)/3;
					b=a+d1;
					c=b+d2;
				}
			}
		}
		//cout<<a<<" "<<b<<c<<endl;
		if(n%3)
			puts("no");
		else
		{
			if(a>n/3||b>n/3||c>n/3)
				puts("no");
			else
				puts("yes");
		}
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<string>
#include<set>
#include<map>
#include<iomanip>
#include<sstream>
#include<functional>
#include<climits>
#define eps 1e-9
const int mod = 1000000007;
using namespace std;

long long x, y, z, t, n, k, d1, d2;;
bool check(){
    if (x >= 0 && y >= 0 && z >= 0 && x % 3 == 0 && y % 3 == 0 && z % 3 == 0) {
        x /= 3;
        y /= 3;
        z /= 3;
        long long mx = max(max(x, y), z);
        if ((n - (mx - x) - (mx - y) - (mx - z)) >= 0 && (n - (mx - x) - (mx - y) - (mx - z)) % 3 == 0){
            cout << "yes" << endl;
            return 1;
        }
    }
    return 0;
}
int main()
{
    scanf("%I64d", &t);
    while (t--) {
        cin >> n >> k >> d1 >> d2;
        scanf("%I64d %I64d %I64d %I64d", &n, &k, &d1, &d2);
        n -= k;
        x = 2 * d1 + d2 + k;
        y = k - d1 + d2;
        z = k - d1 - 2 * d2;
        if (check()) continue;
        x = d2 - 2 * d1 + k;
        y = k + d1 + d2;
        z = k + d1 - 2 * d2;
        if (check()) continue;
        x = 2 * d1 - d2 + k;
        y = k - d1 - d2;
        z = k + 2 * d2 - d1;
        if (check()) continue;
        x = k - 2 * d1 - d2;
        y = k - d2 + d1;
        z = k + 2 * d2 + d1;
        if (check()) continue;
        cout << "no" << endl;
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<string>
#include<set>
#include<map>
#include<iomanip>
#include<sstream>
#include<functional>
#include<climits>
#define eps 1e-9
const int mod = 1000000007;
using namespace std;

long long x, y, z, t, n, k, d1, d2;;
bool check(){
    if (x >= 0 && y >= 0 && z >= 0 && x % 3 == 0 && y % 3 == 0 && z % 3 == 0) {
        x /= 3;
        y /= 3;
        z /= 3;
        long long mx = max(max(x, y), z);
        if ((n - (mx - x) - (mx - y) - (mx - z)) >= 0 && (n - (mx - x) - (mx - y) - (mx - z)) % 3 == 0){
            cout << "yes" << endl;
            return 1;
        }
    }
    return 0;
}
int main()
{
    scanf("%I64d", &t);
    while (t--) {
        scanf("%I64d %I64d %I64d %I64d", &n, &k, &d1, &d2);
        n -= k;
        x = 2 * d1 + d2 + k;
        y = k - d1 + d2;
        z = k - d1 - 2 * d2;
        if (check()) continue;
        x = d2 - 2 * d1 + k;
        y = k + d1 + d2;
        z = k + d1 - 2 * d2;
        if (check()) continue;
        x = 2 * d1 - d2 + k;
        y = k - d1 - d2;
        z = k + 2 * d2 - d1;
        if (check()) continue;
        x = k - 2 * d1 - d2;
        y = k - d2 + d1;
        z = k + 2 * d2 + d1;
        if (check()) continue;
        cout << "no" << endl;
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<string>
#include<set>
#include<map>
#include<iomanip>
#include<sstream>
#include<functional>
#include<climits>
#define eps 1e-9
const int mod = 1000000007;
using namespace std;

long long x, y, z, t, n, k, d1, d2;;
bool check(){
    if (x >= 0 && y >= 0 && z >= 0 && x % 3 == 0 && y % 3 == 0 && z % 3 == 0) {
        x /= 3;
        y /= 3;
        z /= 3;
        long long mx = max(max(x, y), z);
        if ((n - (mx - x) - (mx - y) - (mx - z)) >= 0 && (n - (mx - x) - (mx - y) - (mx - z)) % 3 == 0){
            cout << "yes" << endl;
            return 1;
        }
    }
    return 0;
}
int main()
{
    cin >> t;
    while (t--) {
        cin >> n >> k >> d1 >> d2;
        n -= k;
        x = 2 * d1 + d2 + k;
        y = k - d1 + d2;
        z = k - d1 - 2 * d2;
        if (check()) continue;
        x = d1 - 2 * d1 + k;
        y = k + d1 + d2;
        z = k + d1 - 2 * d2;
        if (check()) continue;
        x = 2 * d1 - d2 + k;
        y = k - d1 - d2;
        z = k + 2 * d2 - d1;
        if (check()) continue;
        x = k - 2 * d1 - d2;
        y = k - d2 + d1;
        z = k + 2 * d2 + d1;
        if (check()) continue;
        cout << "no" << endl;
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<string>
#include<set>
#include<map>
#include<iomanip>
#include<sstream>
#include<functional>
#include<climits>
#define eps 1e-9
const int mod = 1000000007;
using namespace std;

long long x, y, z, t, n, k, d1, d2;;
bool check(){
    if (x >= 0 && y >= 0 && z >= 0 && x % 3 == 0 && y % 3 == 0 && z % 3 == 0) {
        x /= 3;
        y /= 3;
        z /= 3;
        long long mx = max(max(x, y), z);
        if ((n - (mx - x) - (mx - y) - (mx - z)) >= 0 && (n - (mx - x) - (mx - y) - (mx - z)) % 3 == 0){
            cout << "yes" << endl;
            return 1;
        }
    }
    return 0;
}
int main()
{
    cin >> t;
    while (t--) {
        cin >> n >> k >> d1 >> d2;
        n -= k;
        x = 2 * d1 + d2 + k;
        y = k - d1 + d2;
        z = k - d1 - 2 * d2;
        if (check()) continue;
        x = d2 - 2 * d1 + k;
        y = k + d1 + d2;
        z = k + d1 - 2 * d2;
        if (check()) continue;
        x = 2 * d1 - d2 + k;
        y = k - d1 - d2;
        z = k + 2 * d2 - d1;
        if (check()) continue;
        x = k - 2 * d1 - d2;
        y = k - d2 + d1;
        z = k + 2 * d2 + d1;
        if (check()) continue;
        cout << "no" << endl;
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<stdio.h>
#include<algorithm>
using namespace std;

typedef long long ll;

int main()
{
    ll T;
    cin >> T;
    while (T--)
    {
        ll n, k, d1, d2;
        scanf("%I64d%I64d%I64d%I64d", &n, &k, &d1, &d2);
        ll a[3];
        for (int i = 0; i < 3; i++)
            a[i] = k / 3;
        a[0] += d1; a[2] += d2;
        ll t = max(a[0], max(a[1], a[2])) * 3 - (a[0] + a[1] + a[2]);
        if ((n - k - t) % 3 == 0 && n - k - t >= 0)
            printf("yes\n");
        else
            printf("no\n");
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<stdio.h>
#include<algorithm>
using namespace std;

typedef long long ll;

int main()
{
    ll T;
    cin >> T;
    while (T--)
    {
        ll n, k, d1, d2;
        bool temp[4] = { 0, 0, 0, 0 };
        scanf("%I64d%I64d%I64d%I64d", &n, &k, &d1, &d2);
        ll a[4][3] = { { d1, 0, d2 }, { 0, d1, d2 + d1 }, { d1 + d2, d2, 0 }, { 0, d1, d1 - d2 } };
        ll sum[4] = { 0, 0, 0, 0 };
        for (int i = 0; i < 4; i++)
            for (int j = 0; j < 3; j++)
                sum[i] += a[i][j];
        for (int i = 0; i < 4; i++)
        {
            if ((k - sum[i]) % 3 || (k < sum[i]))
            {
                temp[i] = 1;
                continue;
            }
            ll tt = (k - sum[i]) / 3;
            for (int j = 0; j < 3; j++)
                a[i][j] += tt;
        }
        ll ma[4] = { -1, -1, -1, -1 };
        for (int i = 0; i < 4; i++)
        {
            if (temp[i]==1)
                continue;
            for (int j = 0; j < 3; j++)
                ma[i] = max(ma[i], a[i][j]);
        }
        ll tete[4] = { 0, 0, 0, 0 };
        for (int i = 0; i < 4; i++)
        {
            if (temp[i])
                continue;
            for (int j = 0; j < 3; j++)
                tete[i] += ma[i] - a[i][j];
        }
        bool f = 0;
        for (int i = 0; i < 4; i++)
        {
            if (temp[i])
                continue;
            if (n - k >= tete[i] && (n - k - tete[i]) % 3 == 0)
            {
                f = 1;
                break;
            }
        }
        if (f)
            printf("yes\n");
        else
            printf("no\n");
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;

#define maxm 2010
#define inf (1<<29)
#define ii __int64

#define pi  acos(-1.0)
#define eps 1e-9
#define iseq(a,b) (fabs(a-b)<eps)

#define pii pair<int,int>
#define mp  make_pair
#define uu first
#define vv second

ii on(ii n,ii k){ return (n|(1<<k)); }
ii off(ii n,ii k){ return (n-(n&(1<<k))); }
bool chck(ii n,ii k){ return (n&(1<<k)); }

ii mini(ii a,ii b){ if(a<b) return a;  return b;  }
ii maxi(ii a,ii b){ if(a>b) return a;  return b;  }

ii n,K,d1,d2;

ii cal(ii rem,ii v1,ii v2,ii v3){

    ii minn=mini(v1,v2);
    minn=mini(minn,v3);

    if(minn<0){
        return cal(rem,v1-minn,v2-minn,v3-minn);
    }

    if(v1+v2+v3>K) return 0;

    ii maxx=maxi(v1,v2);
    maxx=maxi(maxx,v3);

    ii req=(maxx-v1)+(maxx-v2)+(maxx-v3);

    rem-=req;

    if(rem<0) return 0;

    if(rem%3) return 0;

    return 1;
}

int main(){

    int i,j,k,l,test,t=1;

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    scanf("%d",&test);

    while(test--){

        scanf("%I64d %I64d %I64d %I64d",&n,&K,&d1,&d2);

        ii rem=n-K;

        // 1st>2nd , 2nd>3rd
        if(cal(rem,d1+d2,d2,0)){
            puts("yes");
            continue;
        }

        // 1st<2nd , 2nd<3rd
        if(cal(rem,0,d1,d1+d2)){
            puts("yes");
            continue;
        }

        // 1st<2nd , 2nd>3rd
        if(cal(rem,0,d1,d1-d2)){
            puts("yes");
            continue;
        }

        // 1st>2nd , 2nd<3rd
        if(cal(rem,d1,0,d2)){
            puts("yes");
            continue;
        }

        puts("no");

    }

    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;

#define maxm 2010
#define inf (1<<29)
#define ii __int64

#define pi  acos(-1.0)
#define eps 1e-9
#define iseq(a,b) (fabs(a-b)<eps)

#define pii pair<int,int>
#define mp  make_pair
#define uu first
#define vv second

ii on(ii n,ii k){ return (n|(1<<k)); }
ii off(ii n,ii k){ return (n-(n&(1<<k))); }
bool chck(ii n,ii k){ return (n&(1<<k)); }

ii mini(ii a,ii b){ if(a<b) return a;  return b;  }
ii maxi(ii a,ii b){ if(a>b) return a;  return b;  }

ii n,K,d1,d2;

ii cal(ii rem,ii v1,ii v2,ii v3){

    ii minn=mini(v1,v2);
    minn=mini(minn,v3);

    if(minn<0){
        return cal(rem,v1-minn,v2-minn,v3-minn);
    }

    if(v1+v2+v3>K) return 0;

    ii rem1=K-(v1+v2+v3);
    if(rem1%3) return 0;

    ii maxx=maxi(v1,v2);
    maxx=maxi(maxx,v3);

    ii req=(maxx-v1)+(maxx-v2)+(maxx-v3);

    rem-=req;

    if(rem<0) return 0;

    if(rem%3) return 0;

    return 1;
}

int main(){

    int i,j,k,l,test,t=1;

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    scanf("%d",&test);

    while(test--){

        scanf("%I64d %I64d %I64d %I64d",&n,&K,&d1,&d2);

        ii rem=n-K;

        // 1st>2nd , 2nd>3rd
        if(cal(rem,d1+d2,d2,0)){
            puts("yes");
            continue;
        }

        // 1st<2nd , 2nd<3rd
        if(cal(rem,0,d1,d1+d2)){
            puts("yes");
            continue;
        }

        // 1st<2nd , 2nd>3rd
        if(cal(rem,0,d1,d1-d2)){
            puts("yes");
            continue;
        }

        // 1st>2nd , 2nd<3rd
        if(cal(rem,d1,0,d2)){
            puts("yes");
            continue;
        }

        puts("no");

    }

    return 0;
}


#include <sstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
using namespace std;

#define maximum(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))

int gcd (int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}

int main() {
	int n;

	cin >> n;

	int a[4];

	int t, k, d1, d2;
	bool d;
	for (int i = 0; i < n; i++) {
		cin >> t >> k >> d1 >> d2;
		a[0] = maximum(d1, d2) + abs(d2 - d1);
		a[1] = 2*d2 + d1;
		a[2] = 2*d1 + d2;
		a[3] = d1 + d2;
		d = false;
		int j;
		for (j = 0; j < 4; j++) {
			if (!d && a[j] <= t-k && ((t-k-a[j]) % 3 == 0)) {
				if (j == 0 && a[3] <= k && ((k - a[3]) % 3 == 0)) d = true;
				if (j == 1 && a[2] <= k && ((k - a[2]) % 3 == 0)) d = true;
				if (j == 2 && a[1] <= k && ((k - a[1]) % 3 == 0)) d = true;
				if (j == 3 && a[0] <= k && ((k - a[0]) % 3 == 0)) d = true;
			}
		}
		if (d) cout << "yes";
		else cout << "no";
		cout << endl;
	}

	return 0;
}


#include <sstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
using namespace std;

#define maximum(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define abs(a) (((a) > 0) ? (a) : -(a));

int gcd (int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}

int main() {
	int n;

	cin >> n;

	long long a[4];

	long long t, k, d1, d2;
	bool d;
	for (long long i = 0; i < n; i++) {
		cin >> t >> k >> d1 >> d2;
		a[0] = maximum(d1, d2) + abs(d2 - d1);
		a[1] = 2*d2 + d1;
		a[2] = 2*d1 + d2;
		a[3] = d1 + d2;
		d = false;
		int j;
		for (j = 0; j < 4; j++) {
			if (!d && a[j] <= t-k && ((t-k-a[j]) % 3 == 0)) {
				if (j == 0 && a[3] <= k && ((k - a[3]) % 3 == 0)) d = true;
				if (j == 1 && a[2] <= k && ((k - a[2]) % 3 == 0)) d = true;
				if (j == 2 && a[1] <= k && ((k - a[1]) % 3 == 0)) d = true;
				if (j == 3 && a[0] <= k && ((k - a[0]) % 3 == 0)) d = true;
			}
		}
		if (d) cout << "yes";
		else cout << "no";
		cout << endl;
	}

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long Int;
Int n,k,d1,d2,tar;
void read()
{
	scanf("%I64d%I64d%I64d%I64d",&n,&k,&d1,&d2);
}
bool check(Int x1,Int x2)
{
	if((k-x1-x2)%3)return false;
	Int x0=(k-x1-x2)/3;
	if(x0+x1<0||x0+x2<0||x0<0)return false;
	if(x0+x1>tar||x0+x2>tar||x0>tar)return false;
	return true;
}
bool solve()
{
	if(n%3)return false;
	tar=n/3;
	if(check(d1,d2))return true;
	if(check(-d1,d2))return true;
	if(check(d1,-d2))return true;
	return false;
}
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		read();
	    if(solve())puts("yes");
	    else puts("no");
	}
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long Int;
Int n,k,d1,d2,tar;
void read()
{
	scanf("%I64d%I64d%I64d%I64d",&n,&k,&d1,&d2);
}
bool check(Int x1,Int x2)
{
	if((k-x1-x2)%3)return false;
	Int x0=(k-x1-x2)/3;
	if(x0+x1<0||x0+x2<0||x0<0)return false;
	if(x0+x1>tar||x0+x2>tar||x0>tar)return false;
	return true;
}
bool solve()
{
	if(n%3)return false;
	tar=n/3;
	if(check(d1,d2))return true;
	if(check(-d1,d2))return true;
	if(check(d1,-d2))return true;
	if(check(-d1,-d2))return true;
	return false;
}
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		read();
	    if(solve())puts("yes");
	    else puts("no");
	}
}


#define _CRT_SECURE_NO_WARNINGS
//#pragma comment(linker, "/STACK:100000000")
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <stdio.h>
#include <vector>
#include <map>
#include <time.h>

#define ll long long
#define ld long double
#define FOR(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define FORN(i, b) for(int i=0; i<(int) (b); i++)
#define FORZ(i, a, b) for (int i=(int)(a); i>=(int)(b); --i)
#define mp make_pair
#define fs first
#define sc second
#define pii pair<int, int>
#define plenn pair<lenn, lenn>
#define vii vector<int>
#define vlenn vector<lenn>
#define pb push_back
#define ppb pop_back
#define bg begin()
#define ed end()
#define rsz resize
#define alenn(a) (a).bg, (a).ed
#define len length()
#define ext return 0;
#define pi 3.141592653589793238462643383279
//lenn gcd(lenn a, lenn b) { if (a == 0 || b == 0) return (a + b); if (a > b) return (gcd(a%b, b)); return (gcd(a, b % a)); }

//lenn lcm(lenn a, lenn b) { return ((a *b / gcd(a, b))); }
int sqr(int x) { return (x*x); }

#define MAX 100100 //53
#define INF 1000000007
#define y1 yy1
#define eps 0.0000000001
void out(){ puts("NO"); exit(0); }

#define ls (v << 1)
#define rs (v << 1)+1
using namespace std;

ll n, k, d1, d2, x, y, z;

bool b(ll f, ll s, ll t){
	if (n % 3) return false;
	ll z = n / 3;
	if (f<0 || f>z || s <0 || s>z || t<0 || t>z) return false;
	return true;
}
bool a(ll d1, ll d2){
	if ((k - d1 - d2) % 3) return false;
	ll s = (k - d1 - d2) / 3;
	ll f = s + d1, t = s + d2;
	return b(f, s, t);
}

int main(){
	cin >> n;
	FORN(z2, n) {
		scanf("%I64d %I64d %I64d %I64d", &n, &k, &d1, &d2);
		bool ans = 0;
		for (int j = -1; j < 2; j+=2)
		for (int i = -1; i < 2; i += 2) {
			ans = ans || a(d1*i, d2*j);
		}
		puts(ans ? "yes" : "no");
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
//#pragma comment(linker, "/STACK:100000000")
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <stdio.h>
#include <vector>
#include <map>
#include <time.h>

#define ll long long
#define ld long double
#define FOR(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define FORN(i, b) for(int i=0; i<(int) (b); i++)
#define FORZ(i, a, b) for (int i=(int)(a); i>=(int)(b); --i)
#define mp make_pair
#define fs first
#define sc second
#define pii pair<int, int>
#define plenn pair<lenn, lenn>
#define vii vector<int>
#define vlenn vector<lenn>
#define pb push_back
#define ppb pop_back
#define bg begin()
#define ed end()
#define rsz resize
#define alenn(a) (a).bg, (a).ed
#define len length()
#define ext return 0;
#define pi 3.141592653589793238462643383279
//lenn gcd(lenn a, lenn b) { if (a == 0 || b == 0) return (a + b); if (a > b) return (gcd(a%b, b)); return (gcd(a, b % a)); }

//lenn lcm(lenn a, lenn b) { return ((a *b / gcd(a, b))); }
int sqr(int x) { return (x*x); }

#define MAX 100100 //53
#define INF 1000000007
#define y1 yy1
#define eps 0.0000000001
void out(){ puts("NO"); exit(0); }

#define ls (v << 1)
#define rs (v << 1)+1
using namespace std;

ll n, k, d1, d2, x, y, z;

bool b(ll f, ll s, ll t){
	if (n % 3) return false;
	ll z = n / 3;
	if (f<0 || f>z || s <0 || s>z || t<0 || t>z) return false;
	return true;
}
bool a(ll d1, ll d2){
	if ((k - d1 - d2) % 3) return false;
	ll s = (k - d1 - d2) / 3;
	ll f = s + d1, t = s + d2;
	return b(f, s, t);
}

int main(){
	cin >> n;
	FORN(z2, n) {
		scanf("%I64d %I64d %I64d %I64d", &n, &k, &d1, &d2);
		bool ans = 0;
		for (int j = -1; j < 2; j+=2)
		for (int i = -1; i < 2; i += 2) {
			if (a(d1*i, d2*j)) ans=1;
		}
		puts(ans ? "yes" : "no");
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
//#pragma comment(linker, "/STACK:100000000")
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <stdio.h>
#include <vector>
#include <map>
#include <time.h>

#define ll long long
#define ld long double
#define FOR(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define FORN(i, b) for(int i=0; i<(int) (b); i++)
#define FORZ(i, a, b) for (int i=(int)(a); i>=(int)(b); --i)
#define mp make_pair
#define fs first
#define sc second
#define pii pair<int, int>
#define plenn pair<lenn, lenn>
#define vii vector<int>
#define vlenn vector<lenn>
#define pb push_back
#define ppb pop_back
#define bg begin()
#define ed end()
#define rsz resize
#define alenn(a) (a).bg, (a).ed
#define len length()
#define ext return 0;
#define pi 3.141592653589793238462643383279
//lenn gcd(lenn a, lenn b) { if (a == 0 || b == 0) return (a + b); if (a > b) return (gcd(a%b, b)); return (gcd(a, b % a)); }

//lenn lcm(lenn a, lenn b) { return ((a *b / gcd(a, b))); }
int sqr(int x) { return (x*x); }

#define MAX 100100 //53
#define INF 1000000007
#define y1 yy1
#define eps 0.0000000001
void out(){ puts("NO"); exit(0); }

#define ls (v << 1)
#define rs (v << 1)+1
using namespace std;

ll n, k, d1, d2, x, y, z;

bool b(ll f, ll s, ll t){
	if (n % 3) return false;
	ll z = n / 3;
	if (f<0 || f>z || s <0 || s>z || t<0 || t>z) return false;
	return true;
}
bool a(ll d1, ll d2){
	if ((k - d1 - d2) % 3) return false;
	ll s = (k - d1 - d2) / 3;
	ll f = s + d1, t = s + d2;
	return b(f, s, t);
}

int main(){
	int t2;
	cin >> t2;
	FORN(z2, t2) {
		cin >> n >> k >> d1 >> d2;
		bool ans = a(d1, d2) || a(-d1, d2) || a(-d1, -d2) || a(d1, -d2);
		puts(ans ? "yes" : "no");
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
//#pragma comment(linker, "/STACK:100000000")
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <stdio.h>
#include <vector>
#include <map>
#include <time.h>

#define ll long long
#define ld long double
#define FOR(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define FORN(i, b) for(int i=0; i<(int) (b); i++)
#define FORZ(i, a, b) for (int i=(int)(a); i>=(int)(b); --i)
#define mp make_pair
#define fs first
#define sc second
#define pii pair<int, int>
#define plenn pair<lenn, lenn>
#define vii vector<int>
#define vlenn vector<lenn>
#define pb push_back
#define ppb pop_back
#define bg begin()
#define ed end()
#define rsz resize
#define alenn(a) (a).bg, (a).ed
#define len length()
#define ext return 0;
#define pi 3.141592653589793238462643383279
//lenn gcd(lenn a, lenn b) { if (a == 0 || b == 0) return (a + b); if (a > b) return (gcd(a%b, b)); return (gcd(a, b % a)); }

//lenn lcm(lenn a, lenn b) { return ((a *b / gcd(a, b))); }
int sqr(int x) { return (x*x); }

#define MAX 100100 //53
#define INF 1000000007
#define y1 yy1
#define eps 0.0000000001
void out(){ puts("NO"); exit(0); }

#define ls (v << 1)
#define rs (v << 1)+1
using namespace std;

ll n, k, d1, d2, x, y, z;

bool b(ll f, ll s, ll t){
	if (n % 3) return false;
	ll z = n / 3;
	if (f<0 || f>z || s <0 || s>z || t<0 || t>z) return false;
	return true;
}
bool a(ll d1, ll d2){
	if ((k - d1 - d2) % 3) return false;
	ll s = (k - d1 - d2) / 3;
	ll f = s + d1, t = s + d2;
	return b(f, s, t);
}

int main(){
	cin >> n;
	FORN(z2, n) {
		scanf("%I64d %I64d %I64d %I64d", &n, &k, &d1, &d2);
		bool ans = 0;
		for (int j = -1; j < 2; j+=2)
		for (int i = -1; i < 2; i += 2) {
			if (a(d1*i, d2*j)) ans=1;
		}
		puts(ans ? "yes" : "no");
	}
//fjiweaojfiweoajf
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
//#pragma comment(linker, "/STACK:100000000")
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <stdio.h>
#include <vector>
#include <map>
#include <time.h>

#define ll long long
#define ld long double
#define FOR(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define FORN(i, b) for(int i=0; i<(int) (b); i++)
#define FORZ(i, a, b) for (int i=(int)(a); i>=(int)(b); --i)
#define mp make_pair
#define fs first
#define sc second
#define pii pair<int, int>
#define plenn pair<lenn, lenn>
#define vii vector<int>
#define vlenn vector<lenn>
#define pb push_back
#define ppb pop_back
#define bg begin()
#define ed end()
#define rsz resize
#define alenn(a) (a).bg, (a).ed
#define len length()
#define ext return 0;
#define pi 3.141592653589793238462643383279
//lenn gcd(lenn a, lenn b) { if (a == 0 || b == 0) return (a + b); if (a > b) return (gcd(a%b, b)); return (gcd(a, b % a)); }

//lenn lcm(lenn a, lenn b) { return ((a *b / gcd(a, b))); }
int sqr(int x) { return (x*x); }

#define MAX 100100 //53
#define INF 1000000007
#define y1 yy1
#define eps 0.0000000001
void out(){ puts("NO"); exit(0); }

#define ls (v << 1)
#define rs (v << 1)+1
using namespace std;

ll n, k, d1, d2, x, y, z;

int main(){
	cin >> n;
	FORN(z2, n) {
		scanf("%I64d %I64d %I64d %I64d", &n, &k, &d1, &d2);
		bool ans = 0;
		for (int j = -1; j < 2; j+=2)
		for (int i = -1; i < 2; i += 2) {
			x = 0;
			y = x + d1*i;
			z = y + d2*j;
			ll r = min(min(x, y), z);
			x -= r;
			y -= r;
			z -= r;
			ll need = max(x, max(y, z)) * 3 - x - y - z;
			if (x + y + z <= k && (k-x-y-z) % 3==0 && need<=n-k) ans = 1;
		}
		puts(ans ? "yes" : "no");
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
//#pragma comment(linker, "/STACK:100000000")
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <stdio.h>
#include <vector>
#include <map>
#include <time.h>

#define ll long long
#define ld long double
#define FOR(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define FORN(i, b) for(int i=0; i<(int) (b); i++)
#define FORZ(i, a, b) for (int i=(int)(a); i>=(int)(b); --i)
#define mp make_pair
#define fs first
#define sc second
#define pii pair<int, int>
#define plenn pair<lenn, lenn>
#define vii vector<int>
#define vlenn vector<lenn>
#define pb push_back
#define ppb pop_back
#define bg begin()
#define ed end()
#define rsz resize
#define alenn(a) (a).bg, (a).ed
#define len length()
#define ext return 0;
#define pi 3.141592653589793238462643383279
//lenn gcd(lenn a, lenn b) { if (a == 0 || b == 0) return (a + b); if (a > b) return (gcd(a%b, b)); return (gcd(a, b % a)); }

//lenn lcm(lenn a, lenn b) { return ((a *b / gcd(a, b))); }
int sqr(int x) { return (x*x); }

#define MAX 100100 //53
#define INF 1000000007
#define y1 yy1
#define eps 0.0000000001
void out(){ puts("NO"); exit(0); }

#define ls (v << 1)
#define rs (v << 1)+1
using namespace std;

ll n, k, d1, d2, x, y, z;

bool b(ll f, ll s, ll t){
	if (n % 3) return false;
	ll z = n / 3;
	if (f<0 || f>z || s <0 || s>z || t<0 || t>z) return false;
	return true;
}
bool a(ll d1, ll d2){
	if ((k - d1 - d2) % 3) return false;
	ll s = (k - d1 - d2) / 3;
	ll f = s + d1, t = s + d2;
	return b(f, s, t);
}

int main(){
	cin >> n;
	FORN(z2, n) {
		scanf("%I64d %I64d %I64d %I64d", &n, &k, &d1, &d2);
		bool ans = a(d1, d2) || a(-d1, d2) || a(-d1, -d2) || a(d1, -d2);
		puts(ans ? "yes" : "no");
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
//#pragma comment(linker, "/STACK:100000000")
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <stdio.h>
#include <vector>
#include <map>
#include <time.h>

#define ll long long
#define ld long double
#define FOR(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define FORN(i, b) for(int i=0; i<(int) (b); i++)
#define FORZ(i, a, b) for (int i=(int)(a); i>=(int)(b); --i)
#define mp make_pair
#define fs first
#define sc second
#define pii pair<int, int>
#define plenn pair<lenn, lenn>
#define vii vector<int>
#define vlenn vector<lenn>
#define pb push_back
#define ppb pop_back
#define bg begin()
#define ed end()
#define rsz resize
#define alenn(a) (a).bg, (a).ed
#define len length()
#define ext return 0;
#define pi 3.141592653589793238462643383279
//lenn gcd(lenn a, lenn b) { if (a == 0 || b == 0) return (a + b); if (a > b) return (gcd(a%b, b)); return (gcd(a, b % a)); }

//lenn lcm(lenn a, lenn b) { return ((a *b / gcd(a, b))); }
int sqr(int x) { return (x*x); }

#define MAX 100010 //53
#define INF 1000000007
#define y1 yy1
#define eps 0.0000000001
void out(){ puts("NO"); exit(0); }

#define ls (v << 1)
#define rs (v << 1)+1
using namespace std;

int t;
ll n, k, d1, d2;
int main(){
	cin >> t;
	FORN(z22, t){
		scanf("%I64d %I64d %I64d %I64d", &n, &k, &d1, &d2);
		if (!k) puts("yes"); else{
			ll x = (k - d1 - d2) / 3;
			ll y = x + d1;
			ll z = y + d2;
			ll p = n - x - y - z;
			int a[] = { x, y, z };
			sort(a, a + 3);
if (x<0) puts("no"); else
			if (k==0 || (a[1] - a[0] + a[2] - a[1]<=p || (!p && x==y && y==z && x==z)) || n+k==0) puts("yes"); else
				puts("no");
		}
	}

	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
	cin.sync_with_stdio(false);
	int t, n, m, diff1, diff2, team1, team2, team3;
	cin >> t;
	vector<bool> ans(t);
	for (int i = 0; i < t; i++){
		cin >> n >> m >> diff1 >> diff2;
		if (diff1 < diff2)
			swap(diff1, diff2);
		if (n % 3)
			ans[i] = 0;
		else{
			ans[i] = 0;
			team1 = diff1 + diff2;
			team2 = diff1;
			if(m >= diff1 + 2 * diff2 && (team1 + (m - diff1 - 2 * diff2) / 3) * 3 <= n)
				ans[i] = 1;
			if (m >= diff2 + 2 * diff1 && (team1 + (m - diff2 - 2 * diff1) / 3) * 3 <= n)
				ans[i] = 1;
			if (m >= 2 * diff1 - diff2 && (team2 + (m - 2 * diff1 + diff2) / 3) * 3 <= n)
				ans[i] = 1;
		}
	}
	for (int k = 0; k < t; k++){
		if (ans[k])
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

bool isGood(long long tot, long long played, long long diff1, long long diff2){
	played -= diff1 + diff2;
	if (played % 3)
		return false;
	played /= 3;
	return played >= 0 && played <= tot / 3 && played + diff1 >= 0 && played + diff1 <= tot / 3 && played + diff2 >= 0 && played + diff2 <= tot / 3;
}

int main(){
	cin.sync_with_stdio(false);
	long long t, n, m, diff1, diff2, currm;
	cin >> t;
	vector<bool> ans(t);
	for (int i = 0; i < t; i++){
		cin >> n >> m >> diff1 >> diff2;
		if (diff1 < diff2)
			swap(diff1, diff2);
		if (n % 3)
			ans[i] = 0;
		else{
			ans[i] = isGood(n, m, diff1, diff1 + diff2) || isGood(n, m, diff1, diff1 - diff2) ||
				isGood(n, m, -diff1, -diff1 + diff2) || isGood(n, m, -diff1, -diff1 - diff2);
		}
	}
	for (int k = 0; k < t; k++){
		if (ans[k])
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

bool isGood(int tot, int played, int diff1, int diff2){
	played -= diff1 + diff2;
	if (played % 3)
		return 0;
	played /= 3;
	return played >= 0 && played <= tot / 3 && played + diff1 >= 0 && played + diff1 <= tot / 3 && played + diff2 >= 0 && played + diff2 <= tot / 3;
}

int main(){
	cin.sync_with_stdio(false);
	int t, n, m, diff1, diff2, currm;
	cin >> t;
	vector<bool> ans(t);
	for (int i = 0; i < t; i++){
		cin >> n >> m >> diff1 >> diff2;
		if (diff1 < diff2)
			swap(diff1, diff2);
		if (n % 3)
			ans[i] = 0;
		else{
			ans[i] = isGood(n, m, diff1, diff1 + diff2) || isGood(n, m, diff1, diff1 - diff2) ||
				isGood(n, m, -diff1, -diff1 + diff2) || isGood(n, m, -diff1, -diff1 - diff2);
		}
	}
	for (int k = 0; k < t; k++){
		if (ans[k])
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
	return 0;
}


#include <cstdio>

using namespace std;

bool check(long long int a,long long int b,long long int c)
{
	return !(a>=b && b>=c);
}

bool build(long long int& a,long long int& b,long long int& c,long long int d1,long long int d2,int ca)
{
	if(ca==0)
	{
		a=d1+d2;
		b=d2;
		c=0;
		if(check(a,b,c))
			return false;
	}
	else if(ca==1)
	{
		a=d1;
		b=0;
		c=d2;
		if(check(a,c,b))
			return false;
	}
	else if(ca==2)
	{
		a=d2-d1;
		b=d2;
		c=0;
		if(check(b,a,c))
			return false;
	}
	else if(ca==3)
	{
		a=0;
		b=d1;
		c=d1-d2;
		if(check(b,c,a))
			return false;
	}
	else if(ca==4)
	{
		a=d1;
		b=0;
		c=d2;
		if(check(c,a,b))
			return false;
	}
	else if(ca==5)
	{
		a=0;
		b=d1;
		c=d1+d2;
		if(check(c,b,a))
			return false;
	}
	else
		return false;

	return true;
}

int main()
{
	long long int t,n,k,d1,d2;
	long long int a,b,c,sum,maxi;
	bool flag;
	int i;

	scanf("%I64d",&t);
	while(t--)
	{
		scanf("%I64d %I64d %I64d %I64d",&n,&k,&d1,&d2);
		if(n%3!=0)
		{
			printf("no\n");
			continue;
		}
		flag=false;

		for(i=0;i<6;i++)
		{
			if(!build(a,b,c,d1,d2,i))
				continue;
			sum=a+b+c;
			if(k<sum || (k-sum)%3!=0)
				continue;
			maxi=a;
			if(maxi<b)
				maxi=b;
			if(maxi<c)
				maxi=c;
			sum=0;
			sum+=maxi-a;
			sum+=maxi-b;
			sum+=maxi-c;
			if(n-k<sum)
				continue;
			if((n-k-sum)%3==0)
			{
				flag=true;
				break;
			}
		}

		if(flag)
			printf("yes\n");
		else
			printf("no\n");
	}
	return 0;
}


#include <cstdio>

using namespace std;

bool check(int a,int b,int c)
{
	return !(a>=b && b>=c);
}

bool build(int& a,int& b,int& c,int d1,int d2,int ca)
{
	if(ca==0)
	{
		a=d1+d2;
		b=d2;
		c=0;
		if(check(a,b,c))
			return false;
	}
	else if(ca==1)
	{
		a=d1;
		b=0;
		c=d2;
		if(check(a,c,b))
			return false;
	}
	else if(ca==2)
	{
		a=d2-d1;
		b=d2;
		c=0;
		if(check(b,a,c))
			return false;
	}
	else if(ca==3)
	{
		a=0;
		b=d1;
		c=d1-d2;
		if(check(b,c,a))
			return false;
	}
	else if(ca==4)
	{
		a=d1;
		b=0;
		c=d2;
		if(check(c,a,b))
			return false;
	}
	else if(ca==5)
	{
		a=0;
		b=d1;
		c=d1+d2;
		if(check(c,b,a))
			return false;
	}
	else
		return false;

	return true;
}

int main()
{
	int t,n,k,d1,d2;
	int a,b,c,i,sum,maxi;
	bool flag;

	scanf("%d",&t);
	while(t--)
	{
		scanf("%d %d %d %d",&n,&k,&d1,&d2);
		flag=false;

		for(i=0;i<6;i++)
		{
			if(!build(a,b,c,d1,d2,i))
				continue;
			sum=a+b+c;
			if(k<sum || (k-sum)%3!=0)
				continue;
			maxi=a;
			if(maxi<b)
				maxi=b;
			if(maxi<c)
				maxi=c;
			sum=0;
			sum+=maxi-a;
			sum+=maxi-b;
			sum+=maxi-c;
			if(n-k<sum)
				continue;
			if((n-k-sum)%3==0)
			{
				flag=true;
				break;
			}
		}

		if(flag)
			printf("yes\n");
		else
			printf("no\n");
	}
	return 0;
}


#include <cstdio>

using namespace std;

bool check(int a,int b,int c)
{
	return !(a>=b && b>=c);
}

bool build(int& a,int& b,int& c,int d1,int d2,int ca)
{
	if(ca==0)
	{
		a=d1+d2;
		b=d2;
		c=0;
		if(check(a,b,c))
			return false;
	}
	else if(ca==1)
	{
		a=d1;
		b=0;
		c=d2;
		if(check(a,c,b))
			return false;
	}
	else if(ca==2)
	{
		a=d2-d1;
		b=d2;
		c=0;
		if(check(b,a,c))
			return false;
	}
	else if(ca==3)
	{
		a=0;
		b=d1;
		c=d1-d2;
		if(check(b,c,a))
			return false;
	}
	else if(ca==4)
	{
		a=d1;
		b=0;
		c=d2;
		if(check(c,a,b))
			return false;
	}
	else if(ca==5)
	{
		a=0;
		b=d1;
		c=d1+d2;
		if(check(c,b,a))
			return false;
	}
	else
		return false;

	return true;
}

int main()
{
	int t,n,k,d1,d2;
	int a,b,c,i,sum,maxi;
	bool flag;

	scanf("%d",&t);
	while(t--)
	{
		scanf("%d %d %d %d",&n,&k,&d1,&d2);
		if(n%3!=0)
		{
			printf("no\n");
			continue;
		}
		flag=false;

		for(i=0;i<6;i++)
		{
			if(!build(a,b,c,d1,d2,i))
				continue;
			sum=a+b+c;
			if(k<sum || (k-sum)%3!=0)
				continue;
			maxi=a;
			if(maxi<b)
				maxi=b;
			if(maxi<c)
				maxi=c;
			sum=0;
			sum+=maxi-a;
			sum+=maxi-b;
			sum+=maxi-c;
			if(n-k<sum)
				continue;
			if((n-k-sum)%3==0)
			{
				flag=true;
				break;
			}
		}

		if(flag)
			printf("yes\n");
		else
			printf("no\n");
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <stack>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>

using namespace std;

long long n, k, d1, d2;
int t;

bool check(long long c1, long long c2, long long c3, long long k)
{
    if (n % 3 != 0)
        return false;
    if (c1 + c2 + c3 > k)
        return false;
    k -= c1 + c2 + c3;
    long long d = max(max(c1 , c2), c3);
    if (k % 3 == 0 && n - ::k - (d - c1) - (d - c2) - (d - c3) >= 0)
        return true;
    if (c1 == 0 && c2 + d1 <= k && (k - c2 - d1) % 3 == 0)
    {
        d = max(c2 + d1, max(c2, c3));
        if (n - ::k - (d - c2 - d1) - (d - c2) - (d - c3) >= 0)
            return true;
        else
            return false;
    }
    if (c3 == 0 && c2 + d2 <= k && (k - c2 - d2) % 3 == 0)
    {
        d = max(c1, max(c2, c2 + d2));
        if (n - ::k - (d - c1) - (d - c2) - (d - c2 - d2) >= 0)
            return true;
        else
            return false;
    }
    return false;

}

int main()
{
    scanf("%d", &t);
    while (t--)
    {
        scanf("%I64d%I64d%I64d%I64d", &n, &k, &d1, &d2);
        if (check(d1, 0, d2, k))
            printf("yes\n");
        else if (d1 > d2)
        {
            if (check(0, d1, d1 - d2, k))
                printf("yes\n");
            else if (check(0, d1, d1 + d2, k))
                printf("yes\n");
            else if (check(d1 + d2, d2, 0, k))
                printf("yes\n");
            else
                printf("no\n");
        }
        else
        {
            if (check(0, d1, d2 + d1, k))
                printf("yes\n");
            else if (check(d2 + d1, d2, 0, k))
                printf("yes\n");
            else if (check(d2 - d1, d2, 0, k))
                printf("yes\n");
            else
                printf("no\n");
        }
    }

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <stack>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>

using namespace std;

long long n, k, d1, d2;
int t;

bool check(long long c1, long long c2, long long c3, long long k)
{
    if (n % 3 != 0)
        return false;
    if (c1 + c2 + c3 > k)
        return false;
    k -= c1 + c2 + c3;
    long long d = max(max(c1 , c2), c3);
    if (k % 3 == 0 && n - ::k - (d - c1) - (d - c2) - (d - c3) >= 0)
        return true;
    if (c1 == 0 && c2 + d1 <= k && (k - c2 - d1) % 3 == 0)
    {
        d = max(c2 + d1, max(c2, c3));
        if (n - ::k - (d - c1) - (d - c2) - (d - c3) >= 0)
            return true;
        else
            return false;
    }
    if (c3 == 0 && c2 + d2 <= k && (k - c2 - d2) % 3 == 0)
    {
        d = max(c1, max(c2, c2 + d2));
        if (n - ::k - (d - c1) - (d - c2) - (d - c3) >= 0)
            return true;
        else
            return false;
    }
    return false;

}

int main()
{
    scanf("%d", &t);
    while (t--)
    {
        scanf("%I64d%I64d%I64d%I64d", &n, &k, &d1, &d2);
        if (check(0, max(d1, d2), max(d1, d2) - min(d1, d2), k))
            printf("yes\n");
        else if (check(d1 + d2, min(d1, d2), 0, k))
            printf("yes\n");
        else if (check(d1, 0, d2, k))
            printf("yes\n");
        else
            printf("no\n");
    }

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <stack>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>

using namespace std;

long long n, k, d1, d2;
int t;

bool check(long long c1, long long c2, long long c3, long long k)
{
    if (n % 3 != 0)
        return false;
    if (c1 + c2 + c3 > k)
        return false;
    k -= c1 + c2 + c3;
    long long d = max(max(c1 , c2), c3);
    if (k % 3 == 0 && n - ::k - (d - c1) - (d - c2) - (d - c3) >= 0)
        return true;
    if (c1 == 0 && c2 + d1 <= k && (k - c2 - d1) % 3 == 0)
    {
        d = max(c2 + d1, max(c2, c3));
        if (n - ::k - (d - c2 + d1) - (d - c2) - (d - c3) >= 0)
            return true;
        else
            return false;
    }
    if (c3 == 0 && c2 + d2 <= k && (k - c2 - d2) % 3 == 0)
    {
        d = max(c1, max(c2, c2 + d2));
        if (n - ::k - (d - c1) - (d - c2) - (d - c2 - d2) >= 0)
            return true;
        else
            return false;
    }
    return false;

}

int main()
{
    scanf("%d", &t);
    while (t--)
    {
        scanf("%I64d%I64d%I64d%I64d", &n, &k, &d1, &d2);
        if (check(0, max(d1, d2), max(d1, d2) - min(d1, d2), k))
            printf("yes\n");
        else if (check(d1 + d2, min(d1, d2), 0, k))
            printf("yes\n");
        else if (check(d1, 0, d2, k))
            printf("yes\n");
        else
            printf("no\n");
    }

    return 0;
}


#include <stdio.h>
#include <iostream>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <complex>
#include <ctime>
#include <iomanip>
#include <cassert>
#include <sstream>
#include <iterator>

using namespace std;

#define file "file"
#define mp make_pair
#define pb push_back
#define xx real()
#define yy imag()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef complex<double> point;

const int MAXN = 1e5 + 5;

ll a[4];

void out(int t){
	if(t) printf("yes\n");
	else printf("no\n");
}

void solve(){
	ll n,k,d1,d2;
	scanf("%I64d%I64d%I64d%I64d",&n,&k,&d1,&d2);
	if(n % 3 != 0){
		out(0);
		return;
	}
	int fl;
	ll s = n / 3;
	if(k - d1 * 2 - d2 >= 0 && (k - d1 * 2 - d2) % 3 == 0){
		a[0] = (k - d1 * 2 - d2) / 3;
		a[1] =  a[0] + d1;
		a[2] =  a[1] + d2;
		fl = 0;
		for(int i = 0;i < 3;i++){
			if(a[i] > s){
				fl = 1; break;
			}
		}
		if(!fl){
			out(1);
			return;
		}
	}
	if(k - d1 * 2 + d2 >= 0 && (k - d1 * 2 + d2) % 3 == 0){
		a[0] = (k - d1 * 2 + d2) / 3;
		a[1] =  a[0] + d1;
		a[2] =  a[1] - d2;
		fl = 0;
		for(int i = 0;i < 3;i++){
			if(a[i] > s){
				fl = 1; break;
			}
		}
		if(!fl){
			out(1);
			return;
		}
	}
	if(k - d1 - d2 >= 0 && (k - d1 - d2) % 3 == 0){
		a[1] = (k - d1 - d2) / 3;
		a[0] =  a[1] + d1;
		a[2] =  a[1] + d2;
		fl = 0;
		for(int i = 0;i < 3;i++){
			if(a[i] > s){
				fl = 1; break;
			}
		}
		if(!fl){
			out(1);
			return;
		}
	}
	if(k - d1 + d2 >= 0 && (k - d1 + d2) % 3 == 0){
		a[1] = (k - d1 + d2) / 3;
		a[0] =  a[1] + d1;
		a[2] =  a[1] - d2;
		fl = 0;
		for(int i = 0;i < 3;i++){
			if(a[i] > s){
				fl = 1; break;
			}
		}
		if(!fl){
			out(1);
			return;
		}
	}
	out(0);
}

int main()
{
	//assert(freopen(file".in","r",stdin)); assert(freopen(file".out","w",stdout));
	#ifndef ONLINE_JUDGE
	assert(freopen("input.txt","r",stdin));
	assert(freopen("output.txt","w",stdout));
	#endif
	int t = 1;
	scanf("%d",&t);
	while(t--){
		solve();
	}
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <complex>
#include <ctime>
#include <iomanip>
#include <cassert>
#include <sstream>
#include <iterator>

using namespace std;

#define file "file"
#define mp make_pair
#define pb push_back
#define xx real()
#define yy imag()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef complex<double> point;

const int MAXN = 1e5 + 5;

ll a[4];

void out(int t){
	if(t) printf("yes\n");
	else printf("no\n");
}

void solve(){
	ll n,k,d1,d2;
	scanf("%I64d%I64d%I64d%I64d",&n,&k,&d1,&d2);
	if(n % 3 != 0){
		out(0);
		return;
	}
	int fl;
	ll s = n / 3;
	if(k - d1 * 2 - d2 >= 0 && (k - d1 * 2 - d2) % 3 == 0){
		a[0] = (k - d1 * 2 - d2) / 3;
		a[1] =  a[0] + d1;
		a[2] =  a[1] + d2;
		fl = 0;
		for(int i = 0;i < 3;i++){
			if(a[i] > s || a[i] < 0){
				fl = 1; break;
			}
		}
		if(!fl){
			out(1);
			return;
		}
	}
	if(k - d1 * 2 + d2 >= 0 && (k - d1 * 2 + d2) % 3 == 0){
		a[0] = (k - d1 * 2 + d2) / 3;
		a[1] =  a[0] + d1;
		a[2] =  a[1] - d2;
		fl = 0;
		for(int i = 0;i < 3;i++){
			if(a[i] > s || a[i] < 0){
				fl = 1; break;
			}
		}
		if(!fl){
			out(1);
			return;
		}
	}
	if(k - d1 - d2 >= 0 && (k - d1 - d2) % 3 == 0){
		a[1] = (k - d1 - d2) / 3;
		a[0] =  a[1] + d1;
		a[2] =  a[1] + d2;
		fl = 0;
		for(int i = 0;i < 3;i++){
			if(a[i] > s || a[i] < 0){
				fl = 1; break;
			}
		}
		if(!fl){
			out(1);
			return;
		}
	}
	if(k - d1 + d2 >= 0 && (k - d1 + d2) % 3 == 0){
		a[1] = (k - d1 + d2) / 3;
		a[0] =  a[1] + d1;
		a[2] =  a[1] - d2;
		fl = 0;
		for(int i = 0;i < 3;i++){
			if(a[i] > s || a[i] < 0){
				fl = 1; break;
			}
		}
		if(!fl){
			out(1);
			return;
		}
	}
	out(0);
}

int main()
{
	//assert(freopen(file".in","r",stdin)); assert(freopen(file".out","w",stdout));
	#ifndef ONLINE_JUDGE
	assert(freopen("input.txt","r",stdin));
	assert(freopen("output.txt","w",stdout));
	#endif
	int t = 1;
	scanf("%d",&t);
	while(t--){
		solve();
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include<iostream>
#include <algorithm>
using namespace std;
#define LL long long
int main()
{
    LL num;
    while(cin>>num){
        while(num--){
        LL n,k,d1,d2;
        cin>>n>>k>>d1>>d2;
        bool judge=false;
        if(d1+d1+d2<=n-k){
            LL re=n-k-d1-d1-d2;
            // cout<<re<<endl;
            if(re%3==0)
                judge=true;
        }
        if(judge)
            cout<<"yes"<<endl;
        else
            cout<<"no"<<endl;
        }
    }

}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:66777216")
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#include<cmath>
#include<memory.h>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<iomanip>
#include<string.h>
#include<sstream>
#include<queue>
using namespace std;
#define mp make_pair
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pii>
#define ppll pair<pll,pll>
#define FOR(i,a,b) for (int i(a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define PI (ld)acos(-1.0)
ll power(ll x, ll y, ll m)
{
	if (!y) return 1;
	if (y % 2) return x*power(x, y - 1, m) % m;
	ll k = power(x, y / 2, m);
	return k*k %m;
}
ll gcd(ll x, ll y)
{
	return y ? gcd(y, x%y) : x;
}
ll lcm(ll x, ll y, ll m)
{
	return x / gcd(x, y)*y%m;
}
ll phi(ll n) {
	ll result = n;
	for (ll i = 2; i*i <= n; ++i)
	if (n % i == 0) {
		while (n % i == 0)
			n /= i;
		result -= result / i;
	}
	if (n > 1)
		result -= result / n;
	return result;
}
ll rev_el(ll x, ll m)
{
	return power(x, phi(m) - 1, m);
}
ll isPrime(ll x)
{
	for (ll i = 2; i*i <= x;++i)
	if (x%i == 0) return false;
	return true;
}
#define NOMOD 1000000000000000007 // 1e18+7
#define INF 1000000007 // 1e9+7
#define EPS 1e-10
#define MOD 1000000007
#define maxn 100005

int main()
{
	ios::sync_with_stdio(0);
	int T;
	cin >> T;
	while (T--)
	{
		ll n, k, d1, d2;
		cin >> n >> k >> d1 >> d2;
		n -= k;
		n -= d1 + d1 + d2;
		if (n < 0 || n % 3) cout << "no\n"; else cout << "yes\n";
	}
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:66777216")
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#include<cmath>
#include<memory.h>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<iomanip>
#include<string.h>
#include<sstream>
#include<queue>
using namespace std;
#define mp make_pair
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pii>
#define ppll pair<pll,pll>
#define FOR(i,a,b) for (int i(a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define PI (ld)acos(-1.0)
ll power(ll x, ll y, ll m)
{
	if (!y) return 1;
	if (y % 2) return x*power(x, y - 1, m) % m;
	ll k = power(x, y / 2, m);
	return k*k %m;
}
ll gcd(ll x, ll y)
{
	return y ? gcd(y, x%y) : x;
}
ll lcm(ll x, ll y, ll m)
{
	return x / gcd(x, y)*y%m;
}
ll phi(ll n) {
	ll result = n;
	for (ll i = 2; i*i <= n; ++i)
	if (n % i == 0) {
		while (n % i == 0)
			n /= i;
		result -= result / i;
	}
	if (n > 1)
		result -= result / n;
	return result;
}
ll rev_el(ll x, ll m)
{
	return power(x, phi(m) - 1, m);
}
ll isPrime(ll x)
{
	for (ll i = 2; i*i <= x;++i)
	if (x%i == 0) return false;
	return true;
}
#define NOMOD 1000000000000000007 // 1e18+7
#define INF 1000000007 // 1e9+7
#define EPS 1e-10
#define MOD 1000000007
#define maxn 100005

int main()
{
	ios::sync_with_stdio(0);
	int T;
	cin >> T;
	while (T--)
	{
		ll n,n1, k, d1, d2;
		bool ans = false;
		cin >> n >> k >> d1 >> d2;

		for (int i = -1; i <= 1;i+=2)
		for (int j = -1; j <= 1; j += 2)
		{
			ll r1 = 0;
			ll r2 = r1 + d1*i;
			ll r3 = r2 + d2*j;
			ll r = min(r1, min(r2, r3));
			r1 += r;
			r2 += r;
			r3 += r;
			ll need = max(r1, max(r2, r3)) * 3 - r1 - r2 - r3;
			if (r1 + r2 + r3 <= k && need <= n - k && (n - k - need) % 3 == 0) ans = true;
		}

		if (!ans) cout << "no\n";
		else cout << "yes\n";
	}
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:66777216")
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#include<cmath>
#include<memory.h>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<iomanip>
#include<string.h>
#include<sstream>
#include<queue>
using namespace std;
#define mp make_pair
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pii>
#define ppll pair<pll,pll>
#define FOR(i,a,b) for (int i(a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define PI (ld)acos(-1.0)
ll power(ll x, ll y, ll m)
{
	if (!y) return 1;
	if (y % 2) return x*power(x, y - 1, m) % m;
	ll k = power(x, y / 2, m);
	return k*k %m;
}
ll gcd(ll x, ll y)
{
	return y ? gcd(y, x%y) : x;
}
ll lcm(ll x, ll y, ll m)
{
	return x / gcd(x, y)*y%m;
}
ll phi(ll n) {
	ll result = n;
	for (ll i = 2; i*i <= n; ++i)
	if (n % i == 0) {
		while (n % i == 0)
			n /= i;
		result -= result / i;
	}
	if (n > 1)
		result -= result / n;
	return result;
}
ll rev_el(ll x, ll m)
{
	return power(x, phi(m) - 1, m);
}
ll isPrime(ll x)
{
	for (ll i = 2; i*i <= x;++i)
	if (x%i == 0) return false;
	return true;
}
#define NOMOD 1000000000000000007 // 1e18+7
#define INF 1000000007 // 1e9+7
#define EPS 1e-10
#define MOD 1000000007
#define maxn 100005

int main()
{
	ios::sync_with_stdio(0);
	int T;
	cin >> T;
	while (T--)
	{
		ll n,n1, k, d1, d2;
		bool ans = false;
		cin >> n >> k >> d1 >> d2;
		n1 = n - k;
		n1 -= d1 + (d1 + d2);
		if (d2+(d1+d2)<=k && n1 >=0 && n1 % 3==0) ans = true;

		n1 = n - k;
		n1 -= abs(d1 - d2) + max(d1, d2);
		if (d1+d2<=k && n1 >= 0 && n1 % 3 == 0) ans = true;

		n1 = n - k;
		n1 -= d2 + (d1 + d2);
		if (d1+(d1+d2)<=k && n1 >= 0 && n1 % 3 == 0) ans = true;

		n1 = n - k;
		n1 -= 2*(d1+d2);
		if (2*(d1+d2) <= k && n1 >= 0 && n1 % 3 == 0) ans = true;

		if (!ans) cout << "no\n";
		else cout << "yes\n";
	}
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:66777216")
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#include<cmath>
#include<memory.h>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<iomanip>
#include<string.h>
#include<sstream>
#include<queue>
using namespace std;
#define mp make_pair
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pii>
#define ppll pair<pll,pll>
#define FOR(i,a,b) for (int i(a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define PI (ld)acos(-1.0)
ll power(ll x, ll y, ll m)
{
	if (!y) return 1;
	if (y % 2) return x*power(x, y - 1, m) % m;
	ll k = power(x, y / 2, m);
	return k*k %m;
}
ll gcd(ll x, ll y)
{
	return y ? gcd(y, x%y) : x;
}
ll lcm(ll x, ll y, ll m)
{
	return x / gcd(x, y)*y%m;
}
ll phi(ll n) {
	ll result = n;
	for (ll i = 2; i*i <= n; ++i)
	if (n % i == 0) {
		while (n % i == 0)
			n /= i;
		result -= result / i;
	}
	if (n > 1)
		result -= result / n;
	return result;
}
ll rev_el(ll x, ll m)
{
	return power(x, phi(m) - 1, m);
}
ll isPrime(ll x)
{
	for (ll i = 2; i*i <= x;++i)
	if (x%i == 0) return false;
	return true;
}
#define NOMOD 1000000000000000007 // 1e18+7
#define INF 1000000007 // 1e9+7
#define EPS 1e-10
#define MOD 1000000007
#define maxn 100005

int main()
{
	ios::sync_with_stdio(0);
	int T;
	cin >> T;
	while (T--)
	{
		ll n,n1, k, d1, d2;
		bool ans = false;
		cin >> n >> k >> d1 >> d2;

		for (int i = -1; i <= 1;i+=2)
		for (int j = -1; j <= 1; j += 2)
		{
			ll r1 = 0;
			ll r2 = r1 + d1*i;
			ll r3 = r2 + d2*j;
			ll r = min(r1, min(r2, r3));
			r1 -= r;
			r2 -= r;
			r3 -= r;
			ll need = max(r1, max(r2, r3)) * 3 - r1 - r2 - r3;
			if ((r1 + r2 + r3) <= k && need <= (n - k) && (n - k - need) % 3 == 0) ans = true;
		}

		if (!ans) cout << "no\n";
		else cout << "yes\n";
	}
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:66777216")
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#include<cmath>
#include<memory.h>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<iomanip>
#include<string.h>
#include<sstream>
#include<queue>
using namespace std;
#define mp make_pair
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pii>
#define ppll pair<pll,pll>
#define FOR(i,a,b) for (int i(a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define PI (ld)acos(-1.0)
ll power(ll x, ll y, ll m)
{
	if (!y) return 1;
	if (y % 2) return x*power(x, y - 1, m) % m;
	ll k = power(x, y / 2, m);
	return k*k %m;
}
ll gcd(ll x, ll y)
{
	return y ? gcd(y, x%y) : x;
}
ll lcm(ll x, ll y, ll m)
{
	return x / gcd(x, y)*y%m;
}
ll phi(ll n) {
	ll result = n;
	for (ll i = 2; i*i <= n; ++i)
	if (n % i == 0) {
		while (n % i == 0)
			n /= i;
		result -= result / i;
	}
	if (n > 1)
		result -= result / n;
	return result;
}
ll rev_el(ll x, ll m)
{
	return power(x, phi(m) - 1, m);
}
ll isPrime(ll x)
{
	for (ll i = 2; i*i <= x;++i)
	if (x%i == 0) return false;
	return true;
}
#define NOMOD 1000000000000000007 // 1e18+7
#define INF 1000000007 // 1e9+7
#define EPS 1e-10
#define MOD 1000000007
#define maxn 100005

int main()
{
	ios::sync_with_stdio(0);
	int T;
	cin >> T;
	while (T--)
	{
		ll n,n1, k, d1, d2;
		bool ans = false;
		cin >> n >> k >> d1 >> d2;
		n1 = n - k;
		n1 -= d1 + (d1 + d2);
		if (d2+(d1+d2)<=k && n1 >=0 && n1 % 3==0) ans = true;

		n1 = n - k;
		n1 -= abs(d1 - d2) + max(d1, d2);
		if (d1+d2<=k && n1 >= 0 && n1 % 3 == 0) ans = true;

		n1 = n - k;
		n1 -= d2 + (d1 + d2);
		if (d1+(d1+d2)<=k && n1 >= 0 && n1 % 3 == 0) ans = true;

		if (!ans) cout << "no\n";
		else cout << "yes\n";
	}
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:66777216")
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#include<cmath>
#include<memory.h>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<iomanip>
#include<string.h>
#include<sstream>
#include<queue>
using namespace std;
#define mp make_pair
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pii>
#define ppll pair<pll,pll>
#define FOR(i,a,b) for (int i(a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define PI (ld)acos(-1.0)
ll power(ll x, ll y, ll m)
{
	if (!y) return 1;
	if (y % 2) return x*power(x, y - 1, m) % m;
	ll k = power(x, y / 2, m);
	return k*k %m;
}
ll gcd(ll x, ll y)
{
	return y ? gcd(y, x%y) : x;
}
ll lcm(ll x, ll y, ll m)
{
	return x / gcd(x, y)*y%m;
}
ll phi(ll n) {
	ll result = n;
	for (ll i = 2; i*i <= n; ++i)
	if (n % i == 0) {
		while (n % i == 0)
			n /= i;
		result -= result / i;
	}
	if (n > 1)
		result -= result / n;
	return result;
}
ll rev_el(ll x, ll m)
{
	return power(x, phi(m) - 1, m);
}
ll isPrime(ll x)
{
	for (ll i = 2; i*i <= x;++i)
	if (x%i == 0) return false;
	return true;
}
#define NOMOD 1000000000000000007 // 1e18+7
#define INF 1000000007 // 1e9+7
#define EPS 1e-10
#define MOD 1000000007
#define maxn 100005

int main()
{
	ios::sync_with_stdio(0);
	int T;
	cin >> T;
	while (T--)
	{
		ll n,n1, k, d1, d2;
		bool ans = false;
		cin >> n >> k >> d1 >> d2;

		for (int i = -1; i <= 1;i+=2)
		for (int j = -1; j <= 1; j += 2)
		{
			ll r1 = 0;
			ll r2 = r1 + d1*i;
			ll r3 = r2 + d2*j;
			ll r = min(r1, min(r2, r3));
			r1 -= r;
			r2 -= r;
			r3 -= r;
			ll need = max(r1, max(r2, r3)) * 3 - r1 - r2 - r3;
			if ((r1 + r2 + r3) <= k && (k-r1-r2-r3)%3==0 && need <= (n - k) && (n - k - need) % 3 == 0) ans = true;
		}

		if (!ans) cout << "no\n";
		else cout << "yes\n";
	}
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<climits>

using namespace std;

int n, m, maxi, mini, cnt, ans, b[100000];
string s;
vector<int> a;
int main()
{
    //freopen("input.txt","r",stdin);
    int t;
    scanf("%d",&t);
    for(int i=0; i<t; i++)
    {
        long long n, k, d1, d2;
        cin >> n >> k >> d1 >> d2;
        if(n%3 != 0)
        {
            printf("no\n");
            continue;
        }
        //1
        long long ost = k - d1 - 2*d2;
        if(ost >= 0 && ost%3 == 0 && ost/3 + d1 + d2 <= n/3)
        {
            printf("yes\n");
            continue;
        }
        //2
        ost = k - d1 - d2;
        if(ost >= 0 && ost%3 == 0 && ost/3 + max(d1 , d2) <= n/3)
        {
            printf("yes\n");
            continue;
        }
        //3
        ost = k - max(d1 , d2) - (abs(d1-d2));
        if(ost >= 0 && ost%3 == 0 && ost/3 + max(d1 , d2) <= n/3)
        {
            printf("yes\n");
            continue;
        }
        //4
        ost = k - 2*d1 - d2;
        if(ost >= 0 && ost%3 == 0 && ost/3 + d1 + d2 <= n/3)
        {
            printf("yes\n");
            continue;
        }
        printf("no\n");
    }

    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<climits>

using namespace std;

int n, m, maxi, mini, cnt, ans, b[100000];
string s;
vector<int> a;
int main()
{
    //freopen("input.txt","r",stdin);
    int t;
    scanf("%d",&t);
    for(int i=0; i<t; i++)
    {
        long long n, k, d1, d2;
        cin >> n >> k >> d1 >> d2;
        if(n%3 != 0 || k<d1+d2)
        {
            printf("no\n");
            continue;
        }
        //1
        long long ost = k - d1 - 2*d2;
        if(ost >= 0 && ost%3 == 0 && ost/3 + d1 + d2 <= n/3)
        {
            printf("yes\n");
            continue;
        }
        //2
        ost = k - d1 - d2;
        if(ost >= 0 && ost%3 == 0 && ost/3 + max(d1 , d2) <= n/3)
        {
            printf("yes\n");
            continue;
        }
        //3
        ost = k - d1 - d2 - (abs(d1-d2));
        if(ost >= 0 && ost%3 == 0 && ost/3 + max(d1 , d2) <= n/3)
        {
            printf("yes\n");
            continue;
        }
        //4
        ost = k - 2*d1 - d2;
        if(ost >= 0 && ost%3 == 0 && ost/3 + d1+d2 <= n/3)
        {
            printf("yes\n");
            continue;
        }
        printf("no\n");
    }

    return 0;
}


n = int(input())
C = [int(s) for s in input().split(" ")]
A = [int(s)-1 for s in input().split(" ")]
al = [False for i in range(0, n)]
ans = 0
for v in range(0, n):
    if al[v]:
        continue
    sequence = []
    while not al[v]:
        sequence.append(v)
        al[v] = True
        v = A[v]
    if v in sequence:
        tek = C[v]
        for j in sequence[sequence.index(v)+1:]:
            tek = min(C[j], tek)
        ans += tek
print(ans)


input()
c = list(map(int, input().split()))
a = list(map(int, input().split()))

u = [0] * len(a)

ans = 0

for i in range(len(a)):
    if u[i] != 0:
        continue
    idx = i
    while u[idx] == 0:
        u[idx] = 1
        idx = a[idx] - 1

    if (u[idx] == 2):
        idx = i
        while u[idx] == 1:
            u[idx] = 2
            idx = a[idx] - 1
        continue

    start = idx
    mn = c[idx]
    u[idx] = 2
    while a[idx] - 1 != start:
        idx = a[idx] - 1
        mn = min(mn, c[idx])
        u[idx] = 2

    idx = i
    while u[idx] == 1:
        u[idx] = 2
        idx = a[idx] - 1
    ans += mn
print(ans)


#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
#include <string>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    return 0;
}


# input
n = input()
a = list(map(int, input().split())) # costs of each room
a_next = list(map(int, input().split())) # a_next[i] : the next room of ith room
for i in range(len(a_next)):
    a_next[i] -= 1

cycles = [] # list of cycles
check = [0]*len(a) # check array (0:unchecked, 1:visited, 2:belongs to a cycle)
path = [] # path of dfs

# dfs function. make cycles along the way
def dfs(v):
    check[v] = 1
    global path
    path.append(v)

    next_v = a_next[v]
    if check[next_v] != 2:
        if check[next_v] == 0:
            dfs(next_v)
        elif check[next_v] == 1: # a new cycle has been found
            cycle = []
            while path[-1] != next_v:
                cycle.append(path[-1])
                path = path[:len(path)-1]
            cycle.append(next_v)
            cycles.append(cycle)

    check[v] = 2
    path = path[:len(path)-1] # remove last element

# make a list of cycles
for i in range(len(a)):
    if check[i] == 0:
        dfs(i)

# add up all minimum costs for each cycle
ans = 0 # answer
for cycle in cycles:
    min_cost = a[cycle[0]]
    for v in cycle:
        if a[v] < min_cost:
            min_cost = a[v]
    ans += min_cost

# print answer
print(ans)


# -------------------------SOLVE STACK OVERFFLOW WHILE DFS
# input
n = input()
a = list(map(int, input().split())) # costs of each room
a_next = list(map(int, input().split())) # a_next[i] : the next room of ith room
for i in range(len(a_next)):
    a_next[i] -= 1

cycles = [] # list of cycles
check = [0]*len(a) # check array (0:unchecked, 1:visited, 2:belongs to a cycle)

# dfs function. make cycles along the way
def dfs(v):
    path = [] # path of dfs
    s = [] # dfs stack

    check[v] = 1
    path.append(v)
    s.append(v)

    while s:
        next_v = a_next[s[-1]]

        if check[next_v] == 0:
            check[next_v] = 1
            path.append(next_v)
            s.append(next_v)
        else:
            if check[next_v] == 1: # a new cycle has been found
                cycle = []
                while path[-1] != next_v:
                    cycle.append(path.pop())
                cycle.append(next_v)
                cycles.append(cycle)
            # empty the stack
            while s:
                check[s.pop()] = 2

# make a list of cycles
for i in range(len(a)):
    if check[i] == 0:
        dfs(i)

# add up all minimum costs for each cycle
ans = 0 # answer
for cycle in cycles:
    min_cost = a[cycle[0]]
    for v in cycle:
        if a[v] < min_cost:
            min_cost = a[v]
    ans += min_cost

# print answer
print(ans)


n = int(input())
costs = [int(x) for x in input().split()]
edges = [int(x) for x in input().split()]
colors = []
graph = {}
c = {}

for i in range(1, n+1):
        graph[i] = []
for i in range(0, len(edges)):
    graph[i+1].append(edges[i])

colors = [0]*(n+5)
result = 0

def analize(v):
    cheaper = 10000000000
    begin = False
    for u in c.keys():
        if c[u] == v:
            if costs[v-1] < cheaper:
                cheaper = costs[v-1]
            begin = True
        if begin and costs[u-1] < cheaper:
            cheaper = costs[u-1]
    if begin:
        return cheaper
    return 0

def dfs(u):
    colors[u] = 1
    for v in graph[u]:
        if colors[v] == 1:
            if u == v:
                c[v] = u
            return v
        if colors[v] == 0:
            c[v] = u
            w = dfs(v)
            if w:
                return w
    colors[u] = 2
    if len(c) > 0:
        if u in c.keys():
            del c[u]
    return None

for u in graph.keys():
    if colors[u] == 0:
        c = {}
        v = dfs(u)
        result += analize(v)
print(result)


costs = []
colors = []
graph = {}
c = {}

def my_solve(n):
    global colors
    global graph
    global costs
    global c
    colors = [0]*(n+5)
    result = 0
    for u in graph.keys():
        if colors[u] == 0:
            c = {}
            v = dfs(u)
            result += analize(v)
    return result

def analize(v):
    global costs
    global c
    cheaper = 10000000000
    begin = False
    for u in c.keys():
        if c[u] == v:
            if costs[v-1] < cheaper:
                cheaper = costs[v-1]
            begin = True
        if begin and costs[u-1] < cheaper:
            cheaper = costs[u-1]
    if begin:
        return cheaper
    return 0

def dfs(u):
    global graph
    global colors
    global costs
    global c
    colors[u] = 1
    for v in graph[u]:
        if colors[v] == 1:
            if u == v:
                c[v] = u
            return v
        if colors[v] == 0:
            c[v] = u
            w = dfs(v)
            if w:
                return w
    colors[u] = 2
    if len(c) > 0:
        if u in c.keys():
            del c[u]
    return None

def test(n,costs1, edges):
    global graph
    global costs
    costs = costs1
    for i in range(1, n+1):
        graph[i] = []
    for i in range(0, len(edges)):
        graph[i+1].append(edges[i])
    return my_solve(n)

if __name__ == '__main__':
    n = int(input())
    costs1 = [int(x) for x in input().split()]
    edges = [int(x) for x in input().split()]
    print(test(n,costs1, edges))


n = int(input())
costs = [int(x) for x in input().split()]
edges = [int(x) for x in input().split()]
colors = []
graph = {}
c = {}

for i in range(1, n+1):
        graph[i] = []
for i in range(0, len(edges)):
    graph[i+1].append(edges[i])

colors = [0]*(n+5)
result = 0

def analize(v):
    cheaper = 10000000000
    begin = False
    for u in c.keys():
        if c[u] == v:
            if costs[v-1] < cheaper:
                cheaper = costs[v-1]
            begin = True
        if begin and costs[u-1] < cheaper:
            cheaper = costs[u-1]
    if begin:
        return cheaper
    return 0

def dfs(u):
    while u:
        colors[u] = 1
        b = False
        for v in graph[u]:
            if colors[v] == 1:
                if u == v:
                    c[v] = u
                u = v
                return v
                b = True
                break
            if colors[v] == 0:
                c[v] = u
                u = v
                b = True
                break
        if not b:
            colors[u] = 2
            if len(c) > 0:
                if u in c.keys():
                    del c[u]
            u = 0
    return u

for u in graph.keys():
    if colors[u] == 0:
        c = {}
        v = dfs(u)
        result += analize(v)
print(result)


costs = []
colors = []
graph = {}

def my_solve(n):
    global colors
    global graph
    global costs
    colors = [0]*(n+5)
    result = 0
    for u in graph.keys():
        if colors[u] == 0:
            c = {}
            c,v = dfs(u,c)
            result += analize(c,v)
    return result

def analize(c, v):
    global costs
    cheaper = 10000000000
    begin = False
    for u in c.keys():
        if c[u] == v:
            if costs[v-1] < cheaper:
                cheaper = costs[v-1]
            begin = True
        if begin and costs[u-1] < cheaper:
            cheaper = costs[u-1]
    if begin:
        return cheaper
    return 0

def dfs(u, c):
    global graph
    global colors
    global costs
    colors[u] = 1
    for v in graph[u]:
        if colors[v] == 1:
            if u == v:
                c[v] = u
            return (c, v)
        if colors[v] == 0:
            c[v] = u
            p,w = dfs(v,c)
            if w:
                return (p,w)
    colors[u] = 2
    if len(c) > 0:
        if u in c.keys():
            del c[u]
    return (c, None)

def test(n,costs1, edges):
    global graph
    global costs
    costs = costs1
    for i in range(1, n+1):
        graph[i] = []
    for i in range(0, len(edges)):
        graph[i+1].append(edges[i])
    return my_solve(n)

if __name__ == '__main__':
    n = int(input())
    costs1 = [int(x) for x in input().split()]
    edges = [int(x) for x in input().split()]
    print(test(n,costs1, edges))


def main():
    n, r = int(input()) + 1, 0
    cc = [0, *map(int, input().split())]
    aa = [0, *map(int, input().split())]
    avail = [True] * n
    for i, a in enumerate(avail):
        if a:
            j = i
            while avail[j]:
                avail[j] = False
                j = aa[j]
            c, j = cc[j], aa[j]
            if c:
                while cc[j]:
                    if c > cc[j]:
                        c = cc[j]
                    cc[j] = 0
                    j = aa[j]
                r += c
            while cc[i]:
                cc[i] = 0
                i = aa[i]
    print(r)

if __name__ == '__main__':
    main()


R=lambda:map(int,raw_input().split())
n=input()
c=R()
a=R()
v=[-1]*n
t=0
for i in range(n):
    x=i
    while v[x]<0:
        v[x]=i
        x=a[x]-1
    if v[x]==i:
        y=x
        z=c[y]
        while a[y]!=x+1:
            y=a[y]-1
            z=min(z,c[y])
        t+=z
print t


n = int(raw_input())

C=[0]+map(int,raw_input().split())
A=[0]+map(int,raw_input().split())
"""

n=10
C=[0,6, 9, 1, 1, 1, 10, 2, 4, 9, 6]
A=[0,5, 3, 4, 2, 6, 8, 9, 1, 10, 7]
"""
if n==1:
    print C[1]
    exit()
#A=[A[i]-1 for i in range(n)]

vis = [0] * (n+1)
ans = 0
for i in range(1,n+1):
    x = i
    while vis[x] == 0:
        vis[x] = i
        x = A[x]
    if vis[x] != i:
        continue
    v = x
    mn = C[x]
    while A[x] != v:
        x = A[x]
        mn = min(mn, C[x])
    ans += mn
print(ans)


n = int(raw_input())

C=map(int,raw_input().split())
A=map(int,raw_input().split())
"""
n=5
C=[1, 2, 3, 2, 10]
A=[1,3,4,3,3]
"""

A=[A[i]-1 for i in range(n)]
vis=[False]*(n)
trp=0

for i in range(n):
    if vis[i]==False:
        flg=True
        tx=[False]*n
        j=i
        while tx[j]==False:
            tx[j]=True
            if vis[j]==True:
                flg=False
                break
            else:
                vis[j]=True
            j=A[j]
        if flg:
            t=A[j]
            tx[t]=True

            mx=C[t]
        #print i,j,t
            while A[t]!=j:
                #print A[t],j
                t=A[t]
                mx=min(mx,C[t])
            #print i,mx
            trp+=mx

print trp
exit()


n = int(raw_input())

C=map(int,raw_input().split())
A=map(int,raw_input().split())
"""
n=5
C=[1, 2, 3, 2, 10]
A=[1,3,4,3,3]
n=10
C=[6, 9, 1, 1, 1, 10, 2, 4, 9, 6]
A=[5, 3, 4, 2, 6, 8, 9, 1, 10, 7]

"""
if n==1:
    print C[0]
    exit()
A=[A[i]-1 for i in range(n)]
vis=[False]*(n)
trp=0

for i in range(n):
    if vis[i]==False:
        flg=True
        tx=[False]*n
        j=i
        while tx[j]==False:
            tx[j]=True
            if vis[j]==True:
                flg=False
                break
            else:
                vis[j]=True
            j=A[j]
        if flg:
            t=A[j]
            mx=min(C[j],C[t])
            #print i,j,t
            while A[t]!=j:
                #print A[t],j
                t=A[t]
                mx=min(mx,C[t])
            #print i,mx
            trp+=mx

print trp
exit()


n = int(raw_input())

C=map(int,raw_input().split())
A=map(int,raw_input().split())
"""
n=5
C=[1, 2, 3, 2, 10]
A=[1,3,4,3,3]
n=10
C=[6, 9, 1, 1, 1, 10, 2, 4, 9, 6]
A=[5, 3, 4, 2, 6, 8, 9, 1, 10, 7]

"""
if n==1:
    print C[0]
    exit()
A=[A[i]-1 for i in range(n)]
vis=[False]*(n)
trp=0

for i in range(n):
    if vis[i]==False:
        flg=True
        tx=[False]*n
        j=i
        while tx[j]==False:
            tx[j]=True
            if vis[j]==True:
                flg=False
                break
            else:
                vis[j]=True
                j=A[j]
        if flg:
            t=j
            mx=C[t]
            #print i,j,t
            while A[t]!=j:
                #print A[t],j
                t=A[t]
                mx=min(mx,C[t])
            #print i,mx
            trp+=mx

print trp
exit()


n = int(raw_input())

C=[0]+map(int,raw_input().split())
A=[0]+map(int,raw_input().split())
"""

n=10
C=[0,6, 9, 1, 1, 1, 10, 2, 4, 9, 6]
A=[0,5, 3, 4, 2, 6, 8, 9, 1, 10, 7]
"""
if n==1:
    print C[0]
    exit()
#A=[A[i]-1 for i in range(n)]

vis = [0] * (n+1)
ans = 0
for i in range(1,n+1):
    x = i
    while vis[x] == 0:
        vis[x] = i
        x = A[x]
    if vis[x] != i:
        continue
    v = x
    mn = C[x]
    while A[x] != v:
        x = A[x]
        mn = min(mn, C[x])
    ans += mn
print(ans)


# import sys
# input = sys.stdin.buffer.readline
from collections import deque

class Graph(object):
	"""docstring for Graph"""
	def __init__(self,n,d): # Number of nodes and d is True if directed
		self.n = n
		self.graph = [[] for i in range(n)]
		self.parent = [-1 for i in range(n)]
		self.directed = d

	def addEdge(self,x,y):
		self.graph[x].append(y)
		if not self.directed:
			self.graph[y].append(x)

	def bfs(self, root): # NORMAL BFS
		self.parent = [-1 for i in range(self.n)]
		queue = [root]
		queue = deque(queue)
		vis = [0]*self.n
		while len(queue)!=0:
			element = queue.popleft()
			vis[element] = 1
			for i in self.graph[element]:
				if vis[i]==0:
					queue.append(i)
					self.parent[i] = element

	def dfs(self, root, ans): # Iterative DFS
		stack=[root]
		vis=[0]*self.n
		stack2=[]
		while len(stack)!=0: # INITIAL TRAVERSAL
			element = stack.pop()
			if vis[element]:
				continue
			vis[element] = 1
			stack2.append(element)
			for i in self.graph[element]:
				if vis[i]==0:
					self.parent[i] = element
					stack.append(i)

		while len(stack2)!=0: # BACKTRACING. Modify the loop according to the question
			element = stack2.pop()
			m = 0
			for i in self.graph[element]:
				if i!=self.parent[element]:
					m += ans[i]
			ans[element] = m
		return ans

	def shortestpath(self, source, dest): # Calculate Shortest Path between two nodes
		self.bfs(source)
		path = [dest]
		while self.parent[path[-1]]!=-1:
			path.append(parent[path[-1]])
		return path[::-1]

	def ifcycle(self, root, vis):
		self.bfs(root)
		queue = [root]
		queue = deque(queue)
		done = {root:1}
		prev = root
		while len(queue)!=0:
			element = queue.popleft()
			prev = element
			vis[element] = 1
			for i in self.graph[element]:
				if i in done:
					cycle = [element]
					while cycle[-1]!=i:
						cycle.append(self.parent[cycle[-1]])
					return (True,cycle)

				if vis[i]==1:
					return (False,-1)

				if vis[i]==0:
					done[i]=1
					queue.append(i)
					vis[i] = 1
		return (False,prev)

	def reroot(self, root, ans):
		stack = [root]
		vis = [0]*n
		while len(stack)!=0:
			e = stack[-1]
			if vis[e]:
				stack.pop()
				# Reverse_The_Change()
				continue
			vis[e] = 1
			for i in graph[e]:
				if not vis[e]:
					stack.append(i)
			if self.parent[e]==-1:
				continue
			# Change_The_Answers()

n = int(input())
g = Graph(n,True)
cost = list(map(int,raw_input().split()))
l = list(map(int,raw_input().split()))
vis = [0]*n
for i in range(n):
	if vis[i]==0:
		curr=i
		while True:
			if vis[curr]==1:
				break
			vis[curr]=1
			if curr!=l[curr]-1:
				g.addEdge(curr,l[curr]-1)
			# print (curr,l[curr],g.graph)
			curr = l[curr]-1
# print (g.graph)
vis = [0]*n
ans = 0
for i in range(n):
	if vis[i]==0:
		temp = g.ifcycle(i, vis)
		if not temp[0]:
			if temp[1]!=-1:
				ans+=cost[temp[1]]
		else:
			m=10**18
			for c in temp[1]:
				m=min(m,cost[c])
			ans+=m
		# print (ans,temp,i)
print (ans)