#include <bits/stdc++.h>

using namespace std;
int cnt[3*(int)1e5 + 10];
int numcnt[3*(int)1e5 + 10];
int st[4*3*(int)1e5 + 10];

int left(int p){return (p << 1);}
int right(int p){return (p << 1)|1;}

void update(int p , int l , int r , int idx)
{
	if(l == r)
	{
		if(l == idx)
			st[p] = st[p] + 1;
	}else
	{
		int mid = (l + r)/2;
		if(mid >= idx)
		{
			update(left(p),l,mid,idx);
		}else
		{
			update(right(p),mid + 1 , r , idx);
		}
		st[p] = st[left(p)] + st[right(p)];
	}
}
int query(int p ,int l , int r , int i ,int j)
{
	if(l >= i && r <= j)
	{
		return st[p];
	}else if(l > j || r < i)
	{
		return 0;
	}else
	{
		return query(left(p), l, (l + r)/2 , i , j) + query(right(p),(l+r)/2 + 1 ,r , i , j);
	}
}

int main()
{
	int n , p;
	scanf("%d %d",&n,&p);
	memset(st , 0, sizeof st);
	memset(cnt,0,sizeof cnt);
	memset(numcnt,0,sizeof numcnt);
	for(int i = 0 ; i < n ; i++)
	{
		int one,two;
		scanf("%d %d",&one,&two);
		cnt[one]++;
		cnt[two]++;
	}
	for(int i = 1; i <= n ;i++)
	{
		numcnt[cnt[i]]++;
	}
	int cummsum[3*(int)1e5 + 10];
	cummsum[0] = 0;
	for(int i= 1; i <= n ;i++)
	{
		cummsum[i] = cummsum[i - 1] + numcnt[i];
	}
	int total = 0;
	for(int i = 1; i <= n ; i++)
	{
		int c = cnt[i];
		int req = max(p  - c,0);
		int sub = (req > 0)? cummsum[req-1]:0;
		int number = cummsum[n] - sub;
		int calc = query(1,0,n,req,n);
		if(number - 1 - calc <= 0)
			continue;
		total += number - 1 - calc;
		update(1,0,n,cnt[i]);
	}
	cout << total << endl;
}


#include <bits/stdc++.h>

using namespace std;
long long cnt[3*(int)1e5 + 10];
long long numcnt[3*(int)1e5 + 10];
long long st[4*3*(int)1e5 + 10];

int left(int p){return (p << 1);}
int right(int p){return (p << 1)|1;}

void update(int p , int l , int r , int idx)
{
	if(l == r)
	{
		if(l == idx)
			st[p] = st[p] + 1;
	}else
	{
		int mid = (l + r)/2;
		if(mid >= idx)
		{
			update(left(p),l,mid,idx);
		}else
		{
			update(right(p),mid + 1 , r , idx);
		}
		st[p] = st[left(p)] + st[right(p)];
	}
}

long long query(int p ,int l , int r , int i ,int j)
{
	if(l >= i && r <= j)
	{
		return st[p];
	}else if(l > j || r < i)
	{
		return 0;
	}else
	{
		return query(left(p), l, (l + r)/2 , i , j) + query(right(p),(l+r)/2 + 1 ,r , i , j);
	}
}

int main()
{
	long long n , p;
	scanf("%lld %lld",&n,&p);
	memset(st , 0, sizeof st);
	memset(cnt,0,sizeof cnt);
	memset(numcnt,0,sizeof numcnt);
	for(int i = 0 ; i < n ; i++)
	{
		int one,two;
		scanf("%d %d",&one,&two);
		cnt[one]++;
		cnt[two]++;
	}
	for(int i = 1; i <= n ;i++)
	{
		numcnt[cnt[i]]++;
	}
	long long cummsum[3*(int)1e5 + 10];
	cummsum[0] = numcnt[0];
	for(int i= 1; i <= n ;i++)
	{
		cummsum[i] = cummsum[i - 1] + numcnt[i];
	}
	long long total = 0;
	for(int i = 1; i <= n ; i++)
	{
		long long c = cnt[i];
		long long req = max(p  - c,0LL);
		long long sub = (req > 0)? cummsum[req-1]:0;
		long long number = cummsum[n] - sub;
		long long calc = query(1,0,n,req,n);
		if(number - (cnt[i] >= req) - calc <= 0)
			continue;
		total += number - (cnt[i] >= req) - calc;
		update(1,0,n,cnt[i]);
	}
	cout << total << endl;
}


#include <bits/stdc++.h>

using namespace std;
long long cnt[3*(int)1e5 + 10];
long long numcnt[3*(int)1e5 + 10];
long long st[4*3*(int)1e5 + 10];

int left(int p){return (p << 1);}
int right(int p){return (p << 1)|1;}

void update(int p , int l , int r , int idx)
{
	if(l == r)
	{
		if(l == idx)
			st[p] = st[p] + 1;
	}else
	{
		int mid = (l + r)/2;
		if(mid >= idx)
		{
			update(left(p),l,mid,idx);
		}else
		{
			update(right(p),mid + 1 , r , idx);
		}
		st[p] = st[left(p)] + st[right(p)];
	}
}
long long query(int p ,int l , int r , int i ,int j)
{
	if(l >= i && r <= j)
	{
		return st[p];
	}else if(l > j || r < i)
	{
		return 0;
	}else
	{
		return query(left(p), l, (l + r)/2 , i , j) + query(right(p),(l+r)/2 + 1 ,r , i , j);
	}
}

int main()
{
	int n , p;
	scanf("%d %d",&n,&p);
	memset(st , 0, sizeof st);
	memset(cnt,0,sizeof cnt);
	memset(numcnt,0,sizeof numcnt);
	for(int i = 0 ; i < n ; i++)
	{
		int one,two;
		scanf("%d %d",&one,&two);
		cnt[one]++;
		cnt[two]++;
	}
	for(int i = 1; i <= n ;i++)
	{
		numcnt[cnt[i]]++;
	}
	long long cummsum[3*(int)1e5 + 10];
	cummsum[0] = numcnt[0];
	for(int i= 1; i <= n ;i++)
	{
		cummsum[i] = cummsum[i - 1] + numcnt[i];
	}
	long long total = 0;
	for(int i = 1; i <= n ; i++)
	{
		long long c = cnt[i];
		long long req = max(p  - c,0);
		long long sub = (req > 0)? cummsum[req-1]:0;
		long long number = cummsum[n] - sub;
		long long calc = query(1,0,n,req,n);
		if(number - 1 - calc <= 0)
			continue;
		total += number - 1 - calc;
		update(1,0,n,cnt[i]);
	}
	cout << total << endl;
}


#include <bits/stdc++.h>

using namespace std;
long long cnt[3*(int)1e5 + 10];
long long numcnt[3*(int)1e5 + 10];
long long st[4*3*(int)1e5 + 10];
long long st2[4*3*(int)1e5 + 10];
int left(int p){return (p << 1);}
int right(int p){return (p << 1)|1;}
vector<int> choose[3*(int)1e5 + 10];

void update(int p , int l , int r , int idx, int val)
{
	if(l == r)
	{
		st[p] = st[p] + val;
	}else
	{
		int mid = (l + r)/2;
		if(mid >= idx)
		{
			update(left(p),l,mid,idx,val);
		}else
		{
			update(right(p),mid + 1 , r , idx,val);
		}
		st[p] = st[left(p)] + st[right(p)];
	}
}

long long query(int p ,int l , int r , int i ,int j)
{
	if(l >= i && r <= j)
	{
		return st[p];
	}else if(l > j || r < i)
	{
		return 0;
	}else
	{
		return query(left(p), l, (l + r)/2 , i , j) + query(right(p),(l+r)/2 + 1 ,r , i , j);
	}
}
void update2(int p , int l , int r , int idx , int val)
{
	if(l == r)
	{
		st2[p] = st2[p] + val;
	}else
	{
		int mid = (l + r)/2;
		if(mid >= idx)
		{
			update2(left(p),l,mid,idx,val);
		}else
		{
			update2(right(p),mid + 1 , r , idx,val);
		}
		st2[p] = st2[left(p)] + st2[right(p)];
	}
}

long long query2(int p ,int l , int r , int i ,int j)
{
	if(l >= i && r <= j)
	{
		return st2[p];
	}else if(l > j || r < i)
	{
		return 0;
	}else
	{
		return query2(left(p), l, (l + r)/2 , i , j) + query2(right(p),(l+r)/2 + 1 ,r , i , j);
	}
}
int main()
{
	long long n , p;
	scanf("%lld %lld",&n,&p);
	memset(st , 0, sizeof st);
	memset(cnt,0,sizeof cnt);
	memset(numcnt,0,sizeof numcnt);
	memset(st2,0,sizeof st2);
	pair<int,int> arr[3*(int)1e5 + 10];
	for(int i = 0 ; i < n ; i++)
	{
		int one,two;
		scanf("%d %d",&one,&two);
		choose[one].push_back(i + 1);
		choose[two].push_back(i + 1);
		arr[i+1] = make_pair(one,two);
		cnt[one]++;
		cnt[two]++;
	}
	for(int i = 1; i <= n ;i++)
	{
		numcnt[cnt[i]]++;
	}
	long long cummsum[3*(int)1e5 + 10];
	cummsum[0] = numcnt[0];
	for(int i= 1; i <= n ;i++)
	{
		update2(1,0,n,cnt[i],1);
		cummsum[i] = cummsum[i - 1] + numcnt[i];
	}
	long long total = 0;
	// cout << query2(1,0,n,3,n) << " QQ\n";
	for(int i = 1; i <= n ; i++)
	{
		long long c = cnt[i];
		long long req = max(p  - c,0LL);
		int s = choose[i].size();
		for(int j = 0 ; j < s ;j++)
		{
			int two = (arr[choose[i][j]].first == i) ?arr[choose[i][j]].second : arr[choose[i][j]].first;
			// cout << i << " " <<  two << " " << cnt[two] << " MALAK\n";
			update2(1,0,n,cnt[two],- 1);
			update2(1,0,n,cnt[two] - 1,1);
			if(two < i)
			{
				update(1,0,n,cnt[two],- 1);
				update(1,0,n,cnt[two] - 1,1);
			}
			cnt[two]--;

		}
		long long number = query2(1,0,n,req,n);
		// long long number = cummsum[n] - sub;
		long long calc = query(1,0,n,req,n);
		for(int j = 0 ; j < s ;j++)
		{
			int two = (arr[choose[i][j]].first == i) ?arr[choose[i][j]].second : arr[choose[i][j]].first;
			cnt[two]++;
			update2(1,0,n,cnt[two],1);
			update2(1,0,n,cnt[two] - 1,-1);
			if(two < i)
			{
				update(1,0,n,cnt[two],1);
				update(1,0,n,cnt[two] - 1,-1);
			}
		}
		// cout << number << " " << cnt[i] << " " << req << " " << calc << endl;
		if(number - (cnt[i] >= req) - calc <= 0)
			continue;
		total += number - (cnt[i] >= req) - calc;
		update(1,0,n,cnt[i],1);
	}
	cout << total << endl;
}


#include <bits/stdc++.h>

using namespace std;
long long cnt[3*(int)1e5 + 10];
long long numcnt[3*(int)1e5 + 10];
long long st[4*3*(int)1e5 + 10];

int left(int p){return (p << 1);}
int right(int p){return (p << 1)|1;}

void update(int p , int l , int r , int idx)
{
	if(l == r)
	{
		if(l == idx)
			st[p] = st[p] + 1;
	}else
	{
		int mid = (l + r)/2;
		if(mid >= idx)
		{
			update(left(p),l,mid,idx);
		}else
		{
			update(right(p),mid + 1 , r , idx);
		}
		st[p] = st[left(p)] + st[right(p)];
	}
}
long long query(int p ,int l , int r , int i ,int j)
{
	if(l >= i && r <= j)
	{
		return st[p];
	}else if(l > j || r < i)
	{
		return 0;
	}else
	{
		return query(left(p), l, (l + r)/2 , i , j) + query(right(p),(l+r)/2 + 1 ,r , i , j);
	}
}

int main()
{
	long long n , p;
	scanf("%lld %lld",&n,&p);
	memset(st , 0, sizeof st);
	memset(cnt,0,sizeof cnt);
	memset(numcnt,0,sizeof numcnt);
	for(int i = 0 ; i < n ; i++)
	{
		int one,two;
		scanf("%d %d",&one,&two);
		cnt[one]++;
		cnt[two]++;
	}
	for(int i = 1; i <= n ;i++)
	{
		numcnt[cnt[i]]++;
	}
	long long cummsum[3*(int)1e5 + 10];
	cummsum[0] = numcnt[0];
	for(int i= 1; i <= n ;i++)
	{
		cummsum[i] = cummsum[i - 1] + numcnt[i];
	}
	long long total = 0;
	for(int i = 1; i <= n ; i++)
	{
		long long c = cnt[i];
		long long req = max(p  - c,0LL);
		long long sub = (req > 0)? cummsum[req-1]:0;
		long long number = cummsum[n] - sub;
		long long calc = query(1,0,n,req,n);
		if(number - 1 - calc <= 0)
			continue;
		total += number - 1 - calc;
		update(1,0,n,cnt[i]);
	}
	cout << total << endl;
}


#include <bits/stdc++.h>

using namespace std;
long long cnt[3*(int)1e5 + 10];
long long numcnt[3*(int)1e5 + 10];
long long st[4*3*(int)1e5 + 10];
long long st2[4*3*(int)1e5 + 10];
int left(int p){return (p << 1);}
int right(int p){return (p << 1)|1;}
vector<int> choose[3*(int)1e5 + 10];

void update(int p , int l , int r , int idx)
{
	if(l == r)
	{
		st[p] = st[p] + 1;
	}else
	{
		int mid = (l + r)/2;
		if(mid >= idx)
		{
			update(left(p),l,mid,idx);
		}else
		{
			update(right(p),mid + 1 , r , idx);
		}
		st[p] = st[left(p)] + st[right(p)];
	}
}

long long query(int p ,int l , int r , int i ,int j)
{
	if(l >= i && r <= j)
	{
		return st[p];
	}else if(l > j || r < i)
	{
		return 0;
	}else
	{
		return query(left(p), l, (l + r)/2 , i , j) + query(right(p),(l+r)/2 + 1 ,r , i , j);
	}
}
void update2(int p , int l , int r , int idx , int val)
{
	if(l == r)
	{
		st2[p] = st2[p] + val;
	}else
	{
		int mid = (l + r)/2;
		if(mid >= idx)
		{
			update2(left(p),l,mid,idx,val);
		}else
		{
			update2(right(p),mid + 1 , r , idx,val);
		}
		st2[p] = st2[left(p)] + st2[right(p)];
	}
}

long long query2(int p ,int l , int r , int i ,int j)
{
	if(l >= i && r <= j)
	{
		return st2[p];
	}else if(l > j || r < i)
	{
		return 0;
	}else
	{
		return query2(left(p), l, (l + r)/2 , i , j) + query2(right(p),(l+r)/2 + 1 ,r , i , j);
	}
}
int main()
{
	long long n , p;
	scanf("%lld %lld",&n,&p);
	memset(st , 0, sizeof st);
	memset(cnt,0,sizeof cnt);
	memset(numcnt,0,sizeof numcnt);
	memset(st2,0,sizeof st2);
	pair<int,int> arr[3*(int)1e5 + 10];
	for(int i = 0 ; i < n ; i++)
	{
		int one,two;
		scanf("%d %d",&one,&two);
		choose[one].push_back(i + 1);
		choose[two].push_back(i + 1);
		arr[i+1] = make_pair(one,two);
		cnt[one]++;
		cnt[two]++;
	}
	for(int i = 1; i <= n ;i++)
	{
		numcnt[cnt[i]]++;
	}
	long long cummsum[3*(int)1e5 + 10];
	cummsum[0] = numcnt[0];
	for(int i= 1; i <= n ;i++)
	{
		update2(1,0,n,cnt[i],1);
		cummsum[i] = cummsum[i - 1] + numcnt[i];
	}
	long long total = 0;
	for(int i = 1; i <= n ; i++)
	{
		long long c = cnt[i];
		long long req = max(p  - c,0LL);
		int s = choose[i].size();
		for(int j = 0 ; j < s ;j++)
		{
			int two = arr[choose[i][j]].second;
			update2(1,0,n,cnt[two],- 1);
			update2(1,0,n,cnt[two] - 1,1);
		}
		long long number = query2(1,0,n,req,n);
		// long long number = cummsum[n] - sub;
		long long calc = query(1,0,n,req,n);
		for(int j = 0 ; j < s ;j++)
		{
			int two = arr[choose[i][j]].second;
			update2(1,0,n,cnt[two],1);
			update2(1,0,n,cnt[two] - 1,-1);
		}
		if(number - (cnt[i] >= req) - calc <= 0)
			continue;
		total += number - (cnt[i] >= req) - calc;
		update(1,0,n,cnt[i]);
	}
	cout << total << endl;
}


#include <bits/stdc++.h>

using namespace std;
int cnt[3*(int)1e5 + 10];
int numcnt[3*(int)1e5 + 10];
int st[4*3*(int)1e5 + 10];

int left(int p){return (p << 1);}
int right(int p){return (p << 1)|1;}

void update(int p , int l , int r , int idx)
{
	if(l == r)
	{
		if(l == idx)
			st[p] = st[p] + 1;
	}else
	{
		int mid = (l + r)/2;
		if(mid >= idx)
		{
			update(left(p),l,mid,idx);
		}else
		{
			update(right(p),mid + 1 , r , idx);
		}
		st[p] = st[left(p)] + st[right(p)];
	}
}
int query(int p ,int l , int r , int i ,int j)
{
	if(l >= i && r <= j)
	{
		return st[p];
	}else if(l > j || r < i)
	{
		return 0;
	}else
	{
		return query(left(p), l, (l + r)/2 , i , j) + query(right(p),(l+r)/2 + 1 ,r , i , j);
	}
}

int main()
{
	int n , p;
	scanf("%d %d",&n,&p);
	memset(st , 0, sizeof st);
	memset(cnt,0,sizeof cnt);
	memset(numcnt,0,sizeof numcnt);
	for(int i = 0 ; i < n ; i++)
	{
		int one,two;
		scanf("%d %d",&one,&two);
		cnt[one]++;
		cnt[two]++;
	}
	for(int i = 1; i <= n ;i++)
	{
		numcnt[cnt[i]]++;
	}
	int cummsum[3*(int)1e5 + 10];
	cummsum[0] = numcnt[0];
	for(int i= 1; i <= n ;i++)
	{
		cummsum[i] = cummsum[i - 1] + numcnt[i];
	}
	int total = 0;
	for(int i = 1; i <= n ; i++)
	{
		int c = cnt[i];
		int req = max(p  - c,0);
		int sub = (req > 0)? cummsum[req-1]:0;
		int number = cummsum[n] - sub;
		int calc = query(1,0,n,req,n);
		if(number - 1 - calc <= 0)
			continue;
		total += number - 1 - calc;
		update(1,0,n,cnt[i]);
	}
	cout << total << endl;
}


#include <bits/stdc++.h>

using namespace std;
long long cnt[3*(int)1e5 + 10];
long long numcnt[3*(int)1e5 + 10];
long long st[4*3*(int)1e5 + 10];
long long st2[4*3*(int)1e5 + 10];
int left(int p){return (p << 1);}
int right(int p){return (p << 1)|1;}
vector<int> choose[3*(int)1e5 + 10];

void update(int p , int l , int r , int idx, int val)
{
	if(l == r)
	{
		st[p] = st[p] + val;
	}else
	{
		int mid = (l + r)/2;
		if(mid >= idx)
		{
			update(left(p),l,mid,idx,val);
		}else
		{
			update(right(p),mid + 1 , r , idx,val);
		}
		st[p] = st[left(p)] + st[right(p)];
	}
}

long long query(int p ,int l , int r , int i ,int j)
{
	if(l >= i && r <= j)
	{
		return st[p];
	}else if(l > j || r < i)
	{
		return 0;
	}else
	{
		return query(left(p), l, (l + r)/2 , i , j) + query(right(p),(l+r)/2 + 1 ,r , i , j);
	}
}
void update2(int p , int l , int r , int idx , int val)
{
	if(l == r)
	{
		st2[p] = st2[p] + val;
	}else
	{
		int mid = (l + r)/2;
		if(mid >= idx)
		{
			update2(left(p),l,mid,idx,val);
		}else
		{
			update2(right(p),mid + 1 , r , idx,val);
		}
		st2[p] = st2[left(p)] + st2[right(p)];
	}
}

long long query2(int p ,int l , int r , int i ,int j)
{
	if(l >= i && r <= j)
	{
		return st2[p];
	}else if(l > j || r < i)
	{
		return 0;
	}else
	{
		return query2(left(p), l, (l + r)/2 , i , j) + query2(right(p),(l+r)/2 + 1 ,r , i , j);
	}
}
int main()
{
	long long n , p;
	scanf("%lld %lld",&n,&p);
	memset(st , 0, sizeof st);
	memset(cnt,0,sizeof cnt);
	memset(numcnt,0,sizeof numcnt);
	memset(st2,0,sizeof st2);
	pair<int,int> arr[3*(int)1e5 + 10];
	for(int i = 0 ; i < n ; i++)
	{
		int one,two;
		scanf("%d %d",&one,&two);
		choose[one].push_back(i + 1);
		choose[two].push_back(i + 1);
		arr[i+1] = make_pair(one,two);
		cnt[one]++;
		cnt[two]++;
	}
	for(int i = 1; i <= n ;i++)
	{
		numcnt[cnt[i]]++;
	}
	long long cummsum[3*(int)1e5 + 10];
	cummsum[0] = numcnt[0];
	for(int i= 1; i <= n ;i++)
	{
		update2(1,0,n,cnt[i],1);
		cummsum[i] = cummsum[i - 1] + numcnt[i];
	}
	long long total = 0;
	// cout << query2(1,0,n,3,n) << " QQ\n";
	for(int i = 1; i <= n ; i++)
	{
		long long c = cnt[i];
		long long req = max(p  - c,0LL);
		int s = choose[i].size();
		for(int j = 0 ; j < s ;j++)
		{
			int two = (arr[choose[i][j]].first == i) ?arr[choose[i][j]].second : arr[choose[i][j]].first;
			// cout << i << " " <<  two << " " << cnt[two] << " MALAK\n";
			update2(1,0,n,cnt[two],- 1);
			update2(1,0,n,cnt[two] - 1,1);
			/*if(two < i)
			{
				update(1,0,n,cnt[two],- 1);
				update(1,0,n,cnt[two] - 1,1);
			}*/
			cnt[two]--;

		}
		long long number = query2(1,0,n,req,n);
		// long long number = cummsum[n] - sub;
		long long calc = query(1,0,n,req,n);
		for(int j = 0 ; j < s ;j++)
		{
			int two = (arr[choose[i][j]].first == i) ?arr[choose[i][j]].second : arr[choose[i][j]].first;
			cnt[two]++;
			update2(1,0,n,cnt[two],1);
			update2(1,0,n,cnt[two] - 1,-1);
			/*if(two < i)
			{
				update(1,0,n,cnt[two],1);
				update(1,0,n,cnt[two] - 1,-1);
			}*/
		}
		// cout << number << " " << cnt[i] << " " << req << " " << calc << endl;
		if(number - (cnt[i] >= req) - calc <= 0)
			continue;
		total += number - (cnt[i] >= req) - calc;
		update(1,0,n,cnt[i],1);
	}
	cout << total << endl;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> graf[5*100010];
vector<int> degrees,deg;
map<pair<int,int>,int> memo;
int degree[5*100010];
int main()
{
    int n,p;
    scanf("%d%d",&n,&p);
    for(int i=0; i<n; i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        if(x>y)swap(x,y);
        x--;
        y--;
        graf[x].push_back(y);
        graf[y].push_back(x);
        degree[x]++;
        degree[y]++;
        memo[make_pair(x,y)]++;
        memo[make_pair(y,x)]++;
    }
    for(int i=0; i<n; i++)
        degrees.push_back(degree[i]);
    sort(degrees.begin(),degrees.end());
    long long sol=0;
    int num=degrees.size();
    for(int i=0; i<n; i++)
    {
        int more=p-degree[i];
        int pos=lower_bound(degrees.begin(),degrees.end(),more)-degrees.begin();
        if(num-pos>0)
        {
            sol+=1LL*(num-pos);
            if(degree[i]>=more)sol--;
        }
    }
    for(int i=0; i<n; i++)
    {
        sort( graf[i].begin(), graf[i].end() );
        graf[i].erase( unique( graf[i].begin(), graf[i].end() ), graf[i].end() );
        for(int j=0; j<graf[i].size(); j++)
        {
            int u=i,v=graf[i][j];
            if(degree[u]+degree[v]>=p&&degree[u]+degree[v]-memo[make_pair(u,v)]<p)
                sol--;
        }
    }
    printf("%lld\n",sol/2LL);
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <ctype.h>
#include <deque>
#include <queue>
#include <cstring>
#include <set>
#include <list>
#include <map>
#include <unordered_map>
#include <stdio.h>

using namespace std;

typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<bool> vb;
typedef std::vector<string> vs;
typedef std::vector<double> vd;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<int> > vvi;
typedef vector<vvi> vvvi;
typedef vector<vll> vvll;
typedef std::vector<std::pair<int, int> > vpi;
typedef vector<vpi> vvpi;
typedef std::pair<int, int> pi;
typedef std::pair<ll, ll> pll;
typedef std::vector<pll> vpll;

const long long mod = 1000000007;

#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define forn(i, a, b) for(int i = a; i < b; i++)

#define pb push_back
#define mp make_pair

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif
    int n,p;
    scanf("%d %d", &n, &p);
    vi cnt(n,0);
    map<pi,int> pr;
    vpi vote;
    forn(i,0,n) {
        int x,y;
        scanf("%d %d", &x, &y);
        x--;
        y--;
        if(y>x) swap(x,y);
        vote.pb(mp(x,y));
        cnt[x]++;
        cnt[y]++;
        pr[mp(x,y)]++;
        pr[mp(y,x)]++;
    }
    ll ans = 0;
    vi s;
    forn(i,0,n) s.pb(cnt[i]);
    sort(all(s));
    forn(i,0,n) {
        int left = p - s[i];
        int u = lower_bound(all(s), left) - s.begin();
        int pairs = n-u;
        if(2*s[i] >= p) pairs--;
        ans += pairs;
    }
    ans /= 2;
    sort(all(vote));
    forn(i,0,n) {
        if(i>0 && vote[i] == vote[i-1]) continue;
        int x= vote[i].first;
        int y= vote[i].second;
        if(cnt[x]+cnt[y]>=p) {
            if(cnt[x]+cnt[y] - pr[vote[i]] < p) ans--;
        }
    }
    cout<<ans;
}


#include <bits/stdc++.h>

using namespace std ;

// magic stl header

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace __gnu_pbds ;

// magic stl header close

typedef pair<int,int> pii ;
typedef long long ll ;

const int sz = 3e5 + 7 ;

typedef tree< pii ,
null_type,
less< pii >,
rb_tree_tag,
tree_order_statistics_node_update> set_t ;

set_t st ;
pii coder_choice[sz] ;
int choose_cont[sz] ;
vector<int> who_choose[sz] ;

int main()
{
	int n , p , x , y ;

	scanf("%d %d",&n,&p);

	for(int i=0 ; i<n ; i++)
	{
		scanf("%d %d",&x,&y);

		x--;
		y--;

		who_choose[x].push_back(i);
		who_choose[y].push_back(i);
		coder_choice[i] = make_pair(x,y);
		choose_cont[x]++;
		choose_cont[y]++;
	}

	for(int i=0 ; i<n ; i++)
		st.insert(make_pair(choose_cont[i],i));

	ll ans = 0 , need ;

	for(int i=0 ; i<n ; i++)
	{
		st.erase(make_pair(choose_cont[i],i));

		for(int j=0 ; j<who_choose[i].size() ; j++)
		{
			x = who_choose[i][j] ;

			y = (coder_choice[x].first == i ? coder_choice[x].second : coder_choice[x].first);

			if(y>i)
			{
				st.erase(make_pair(choose_cont[y],y));
				choose_cont[y]--;
				st.insert(make_pair(choose_cont[y],y));
			}
		}

		need = max(0,p - choose_cont[i]);
		need = st.order_of_key(make_pair(need,-1));
		ans += (int(st.size()) - need) ;

		for(int j=0 ; j<who_choose[i].size() ; j++)
		{
			x = who_choose[i][j] ;

			y = (coder_choice[x].first == i ? coder_choice[x].second : coder_choice[x].first);

			if(y>i)
			{
				st.erase(make_pair(choose_cont[y],y));
				choose_cont[y]++;
				st.insert(make_pair(choose_cont[y],y));
			}
		}
	}

	printf("%lld\n",ans);

	return 0 ;
}

// for tracking


#include <bits/stdc++.h>
#define pi acos(-1)
#define sz(x) (int) x.size()
#define pii pair<int, int>
#define pill pair<int, long long>
#define mii map<int, int>
#define vi vector<int>
#define vll vector<long long>
#define vs vector<string>
#define vb vector<bool>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define popb pop_back
#define all(v) v.begin(),v.end()
#define mset(v, x) memset(v, x, sizeof(v))
#define mset2d(v, x, n) memset(v, x, sizeof(v[0][0]) * n * n)
#define mset2dd(v, x, n, m) memset(v, x, sizeof(v[0][0]) * n * m)
#define debug(x) cerr<<#x<<" : "<<x<<endl
#define debug2(x,y) cerr<<#x<<" : "<<x<<" & "<<#y<<" : "<<y<<endl
#define test() cerr<<"hola papa"<<endl
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;

const ll MAX = 3 * 100005;

ll cmb[MAX];

void init_cmb() {
    cmb[0] = 0LL, cmb[1] = 0LL;
    cmb[2] = 1LL;
    for (ll i = 3LL; i < MAX; ++i) {
        cmb[i] = (cmb[i - 1] * i) / (i - 2);
    }
}

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    init_cmb();
    ll n, p, xi, yi, ans;
    cin >> n >> p;
    vector<ll> m(n + 5, 0LL);
    for (int i = 0; i < n; ++i) {
        cin >> xi >> yi;
        m[xi]++, m[yi]++;
    }
    vll r;
    ll up = 0LL;
    ll low = 0LL;
    for (int i = 1; i <= n; ++i) {
        r.pb(m[i]);
        if (m[i] >= p) ++up;
    }
    sort(all(r));
    int i = 0;
    while (i < n && r[i] < p) {
        auto it = lower_bound(r.begin() + i + 1, r.end(), p - r[i]);
        int pos = it - r.begin();
        if (pos > i && r[i] + r[pos] >= p) {
            ll cnt = n - (ll) pos;
            low += cnt;
        }
        ++i;
    }
    ans = cmb[up] + low;
    cout << ans << endl;
}


#include <bits/stdc++.h>
#define pi acos(-1)
#define sz(x) (int) x.size()
#define pii pair<int, int>
#define pill pair<int, long long>
#define mii map<int, int>
#define vi vector<int>
#define vll vector<long long>
#define vs vector<string>
#define vb vector<bool>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define popb pop_back
#define all(v) v.begin(),v.end()
#define mset(v, x) memset(v, x, sizeof(v))
#define mset2d(v, x, n) memset(v, x, sizeof(v[0][0]) * n * n)
#define mset2dd(v, x, n, m) memset(v, x, sizeof(v[0][0]) * n * m)
#define debug(x) cerr<<#x<<" : "<<x<<endl
#define debug2(x,y) cerr<<#x<<" : "<<x<<" & "<<#y<<" : "<<y<<endl
#define test() cerr<<"hola papa"<<endl
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n, p, xi, yi, ans = 0LL;
    cin >> n >> p;
    map<pii, int> e;
    vi d(n + 5);
    for (int i = 0; i < n; ++i) {
        cin >> xi >> yi;
        if (xi > yi) swap(xi, yi);
        e[{xi, yi}]++, d[xi]++, d[yi]++;
    }
    sort(d.begin() + 1, d.begin() + 1 + n);
    int i = 1;
    while (i <= n) {
        auto it = lower_bound(d.begin() + i + 1, d.begin() + 1 + n, p - d[i]);
        int pos = it - d.begin() - 1;
        ans += max(0LL, n - pos);
        ++i;
    }
    cout << ans << "\n";
}


#include <bits/stdc++.h>
#define pi acos(-1)
#define sz(x) (int) x.size()
#define pii pair<int, int>
#define pill pair<int, long long>
#define mii map<int, int>
#define vi vector<int>
#define vll vector<long long>
#define vs vector<string>
#define vb vector<bool>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define popb pop_back
#define all(v) v.begin(),v.end()
#define mset(v, x) memset(v, x, sizeof(v))
#define mset2d(v, x, n) memset(v, x, sizeof(v[0][0]) * n * n)
#define mset2dd(v, x, n, m) memset(v, x, sizeof(v[0][0]) * n * m)
#define debug(x) cerr<<#x<<" : "<<x<<endl
#define debug2(x,y) cerr<<#x<<" : "<<x<<" & "<<#y<<" : "<<y<<endl
#define test() cerr<<"hola papa"<<endl
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;

const int MAX = 3 * 100005;

ll cmb[MAX];

void init_cmb() {
    cmb[0] = 0, cmb[1] = 0;
    cmb[2] = 1;
    for (int i = 3; i < MAX; ++i) {
        cmb[i] = (cmb[i - 1] * i) / (i - 2);
    }
}

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    init_cmb();
    ll n, p, xi, yi, ans;
    cin >> n >> p;
    map<ll, ll> m;
    for (int i = 0; i < n; ++i) {
        cin >> xi >> yi;
        m[xi]++, m[yi]++;
    }
    vll r;
    ll up = 0LL;
    ll low = 0LL;
    for (auto it: m) {
        r.pb(it.se);
        if (it.se >= p) ++up;
    }
    sort(all(r));
    int i = 0;
    while (i < n && r[i] < p) {
        auto it = lower_bound(r.begin() + i + 1, r.end(), p - r[i]);
        int pos = it - r.begin();
        if (pos > i && r[i] + r[pos] >= p) {
            ll cnt = n - (ll) pos;
            low += cnt;
        }
        ++i;
    }
    ans = cmb[up] + low;
    cout << ans << endl;
}


#include <bits/stdc++.h>
#define pi acos(-1)
#define sz(x) (int) x.size()
#define pii pair<int, int>
#define pill pair<int, long long>
#define mii map<int, int>
#define vi vector<int>
#define vll vector<long long>
#define vs vector<string>
#define vb vector<bool>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define popb pop_back
#define all(v) v.begin(),v.end()
#define mset(v, x) memset(v, x, sizeof(v))
#define mset2d(v, x, n) memset(v, x, sizeof(v[0][0]) * n * n)
#define mset2dd(v, x, n, m) memset(v, x, sizeof(v[0][0]) * n * m)
#define debug(x) cerr<<#x<<" : "<<x<<endl
#define debug2(x,y) cerr<<#x<<" : "<<x<<" & "<<#y<<" : "<<y<<endl
#define test() cerr<<"hola papa"<<endl
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n, p, xi, yi, ans = 0LL;
    cin >> n >> p;
    map<pii, int> e;
    vi d(n + 5);
    vi v(n + 5);
    for (int i = 0; i < n; ++i) {
        cin >> xi >> yi;
        if (xi > yi) swap(xi, yi);
        e[{xi, yi}]++, d[xi]++, d[yi]++;
        v[xi] = d[xi], v[yi] = d[yi];
    }
    sort(v.begin() + 1, v.begin() + 1 + n);
    for (int i = 1; i <= n; ++i) {
        auto it = lower_bound(v.begin() + i + 1, v.begin() + 1 + n, p - v[i]);
        int pos = it - v.begin() - 1;
        ans += max(0LL, n - pos);
    }
    for (auto it: e) {
        int u = it.fi.fi, v = it.fi.se;
        if (d[u] + d[v] >= p && d[u] + d[v] - it.se < p) ans = ans - 1LL;
    }
    cout << ans << "\n";
}


#include <bits/stdc++.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846264338327
#endif // M_PI
#define endl "\n"
#define S struct
#define X first
#define Y second
#define V vector
#ifndef __linux__
#define LLD "%I64d"
#else
#define LLD "%ll""d"
#endif
#define FOR(x, y, z) for (int x = (y); x < (z); ++x)
#define FORR(x, y, z) for (int x = (y); x > (z); --x)
#define GET(a, n) for (int __i = 0; __i < (n); ++__i) cin >> a[__i];
#define GETM(a, n, m) for (int __i = 0; __i < (n); ++__i) for (int __j = 0; __j < m; ++__j) cin >> a[__i][__j];
#define PRINTM(a, n, m) for (int __i = 0; __i < (n); ++__i) { for (int __j = 0; __j < m; ++__j) cout << a[__i][__j] << " ";  cout << endl; };
#define PRINT(a, n) for (int __i = 0; __i < (n); ++__i) cout << a[__i] << " ";
#define IT(a) a.begin(), a.end()
#define SQR(x) (x) * (x)
#define CASE(a, s) cout << "Case #" << a << ": " << s << endl;
#define DEB(a) cout << #a << " = " << (a) << endl; cout.flush();
#define DEBA(a) for (auto __i: a) cout << __i << " "; cout << endl; cout.flush();
#define IFDEB(b, a) if (b) { cout << #a << " = " << (a) << endl; cout.flush(); }
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef pair <LL, LL> PLL;
const int MOD = 1000000007;
S Sync_stdio { Sync_stdio() { cin.tie(NULL); ios_base::sync_with_stdio(false); } } _sync_stdio;
S FAIL { FAIL () { cout << "CHANGE!!!" << endl;}};

int main()
{
    int m, p;
    cin >> m >> p;
    int n = m;
    map <PII, int> edges;
    vector <int> deg(n);
    FOR (i, 0, m) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        ++edges[{x, y}];
        ++edges[{y, x}];
        ++deg[x];
        ++deg[y];
    }
    vector <int> cnt(m + 1);
    FOR (i, 0, n) {
        ++cnt[deg[i]];
    }
    vector <int> suff = cnt;
    suff.push_back(0);
    FORR (i, m, -1) {
        suff[i] += suff[i + 1];
    }
    LL res = 0;
    FOR (i, 0, m + 1) {
        res += (LL)cnt[i] * suff[max(p - i, 0)];
    }
    FOR (i, 0, m + 1) {
        if (2 * i >= p && cnt[i]) {
            res -= cnt[i];
        }
    }
    for (auto i: edges) {
        if (deg[i.X.X] + deg[i.X.Y] >= p && deg[i.X.X] + deg[i.X.Y] - i.Y < p) {
            --res;
        }
    }
    assert(res % 2 == 0);
    cout << res / 2;
}


#include <bits/stdc++.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846264338327
#endif // M_PI
#define endl "\n"
#define S struct
#define X first
#define Y second
#define V vector
#ifndef __linux__
#define LLD "%I64d"
#else
#define LLD "%ll""d"
#endif
#define FOR(x, y, z) for (int x = (y); x < (z); ++x)
#define FORR(x, y, z) for (int x = (y); x > (z); --x)
#define GET(a, n) for (int __i = 0; __i < (n); ++__i) cin >> a[__i];
#define GETM(a, n, m) for (int __i = 0; __i < (n); ++__i) for (int __j = 0; __j < m; ++__j) cin >> a[__i][__j];
#define PRINTM(a, n, m) for (int __i = 0; __i < (n); ++__i) { for (int __j = 0; __j < m; ++__j) cout << a[__i][__j] << " ";  cout << endl; };
#define PRINT(a, n) for (int __i = 0; __i < (n); ++__i) cout << a[__i] << " ";
#define IT(a) a.begin(), a.end()
#define SQR(x) (x) * (x)
#define CASE(a, s) cout << "Case #" << a << ": " << s << endl;
#define DEB(a) cout << #a << " = " << (a) << endl; cout.flush();
#define DEBA(a) for (auto __i: a) cout << __i << " "; cout << endl; cout.flush();
#define IFDEB(b, a) if (b) { cout << #a << " = " << (a) << endl; cout.flush(); }
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef pair <LL, LL> PLL;
const int MOD = 1000000007;
S Sync_stdio { Sync_stdio() { cin.tie(NULL); ios_base::sync_with_stdio(false); } } _sync_stdio;
S FAIL { FAIL () { cout << "CHANGE!!!" << endl;}};

int main()
{
    int m, p;
    scanf("%d%d", &m, &p);
    int n = m;
    map <PII, int> edges;
    vector <int> deg(n);
    FOR (i, 0, m) {
        int x, y;
        scanf("%d%d", &x, &y);
        --x, --y;
        ++edges[{x, y}];
        ++edges[{y, x}];
        ++deg[x];
        ++deg[y];
    }
    vector <int> cnt(m + 1);
    FOR (i, 0, n) {
        ++cnt[deg[i]];
    }
    vector <int> suff = cnt;
    suff.push_back(0);
    FORR (i, m, -1) {
        suff[i] += suff[i + 1];
    }
    LL res = 0;
    FOR (i, 0, m + 1) {
        res += (LL)cnt[i] * suff[max(p - i, 0)];
    }
    FOR (i, 0, m + 1) {
        if (2 * i >= p && cnt[i]) {
            res -= cnt[i];
        }
    }
    for (auto i: edges) {
        if (deg[i.X.X] + deg[i.X.Y] >= p && deg[i.X.X] + deg[i.X.Y] - i.Y < p) {
            --res;
        }
    }
    assert(res % 2 == 0);
    printf("%I64d", res / 2);
}


#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

const int N = 3e5 + 100;

int a[N], b[N], cnt[N];
vector<int> vec[N];

int fen[N];
void upd(int i, int x){ for(i = N - i - 1; i < N; i += i & -i) fen[i] += x; }
int get(int i){
	int res = 0;
	for (i = N - i - 1; i; i -= i & -i) res += fen[i];
	return res;
}

void modify(int x, int q){
	upd(cnt[x], -1);
	cnt[x] += q;
	upd(cnt[x], 1);
}

int main(){
	int n, p; scanf("%d%d", &n, &p);
	upd(0, n);

	for (int i = 0; i < n; i++){
		scanf("%d%d", &a[i], &b[i]);
		a[i]--; b[i]--;
		vec[ a[i] ].push_back(i);
		vec[ b[i] ].push_back(i);

		modify(a[i], 1);
		modify(b[i], 1);
	}

	ll ans = 0;

	for (int i = 0; i < n; i++){
		int v = cnt[i];

		for (int x : vec[i]){
			modify(a[x], -1);
			modify(b[x], -1);
		}

		ans += get(max(0, p - v));
		if (cnt[i] >= p - v) ans--;

		for (int x : vec[i]){
			modify(a[x], 1);
			modify(b[x], 1);
		}
	}

	printf("%lld\n", ans / 2);
}


#include <cstdio>
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
#define ll long long
ll ans;
int n, p, in[300005], arr[300005];
map<pair<int, int>, int> M;
bool cmp(int a, int b)
{
	if (in[a] != in[b])return in[a] < in[b];
	return a < b;
}
int main() {
	scanf("%d %d", &n, &p);
	for (int a, b, i = 1; i <= n; i++) {
		arr[i] = i;
		scanf("%d %d", &a, &b);
		++in[a]; ++in[b];
		M[{min(a, b), max(a, b)}]++;
	}
	sort(arr + 1, arr + n + 1, cmp);
	int L = 1, R = n;
	while (L < R) {
		while (L < R && in[arr[L]] + in[arr[R]] < p)
			++L;
		ans += (R - L);
		--R;
	}
	auto it = M.begin();
	while (it != M.end()) {
		int a = it->first.first; int b = it->first.second;
		if (in[a] + in[b] >= p && in[a] + in[b] - it->second < p)--ans;
		++it;
	}
	cout << ans;
}


//*
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <functional>
#define MOD 1000000007
#define MAX ((1<<30)-1)
#define MAX2 ((1ll<<62)-1)
#pragma warning(disable:4996)
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef set<int>::iterator siit;

int n, p;
vector<int> edge[400000];
ll d[400000];
ll rd[1000000];

int q[400000];
int qi;

int main()
{
    int i, j, k;
    scanf("%d%d", &n, &p);
    for(i=0;i<n;i++)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        x--, y--;
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
    for(i=0;i<n;i++) d[edge[i].size()]++;
    for(i=0;i<n;i++)
    {
        if(d[i]) q[qi++]=i;
    }
    for(i=0;i<qi;i++)
    {
        rd[q[i]*2]+=d[q[i]]*(d[q[i]]-1)/2;
        for(j=i+1;j<qi;j++)
        {
            rd[q[i]+q[j]]+=d[q[i]]*d[q[j]];
        }
    }
    for(i=0;i<n;i++)
    {
        for(auto nex : edge[i])
        {
            if(i > nex) continue;
            rd[edge[i].size()+edge[nex].size()]--;
            rd[edge[i].size()+edge[nex].size()-1]++;
        }
    }
    ll sum=0;
    for(i=p;i<1000000;i++) sum+=rd[i];
    printf("%I64d", sum);
    return 0;
}
//*/


//*
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <functional>
#define MOD 1000000007
#define MAX ((1<<30)-1)
#define MAX2 ((1ll<<62)-1)
#pragma warning(disable:4996)
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef set<int>::iterator siit;

int n, p;
vector<int> edge[400000];
ll d[400000];
ll rd[1000000];

int q[400000];
int qi;

int main()
{
    int i, j, k;
    scanf("%d%d", &n, &p);
    for(i=0;i<n;i++)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        x--, y--;
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
    for(i=0;i<n;i++) sort(edge[i].begin(), edge[i].end());
    for(i=0;i<n;i++) d[edge[i].size()]++;
    for(i=0;i<n;i++)
    {
        if(d[i]) q[qi++]=i;
    }
    for(i=0;i<qi;i++)
    {
        rd[q[i]*2]+=d[q[i]]*(d[q[i]]-1)/2;
        for(j=i+1;j<qi;j++)
        {
            rd[q[i]+q[j]]+=d[q[i]]*d[q[j]];
        }
    }
    for(i=0;i<n;i++)
    {
        int cnt=1;
        int prev=-1;
        for(auto nex : edge[i])
        {
            if(i > nex) continue;
            if(prev == nex)
            {
                cnt++;
            }
            else
            {
                rd[edge[i].size()+edge[prev].size()]--;
                rd[edge[i].size()+edge[prev].size()-cnt]++;
                cnt=1;
            }
            prev=nex;
        }
        rd[edge[i].size()+edge[prev].size()]--;
        rd[edge[i].size()+edge[prev].size()-cnt]++;
    }
    ll sum=0;
    for(i=p;i<1000000;i++) sum+=rd[i];
    printf("%I64d", sum);
    return 0;
}
//*/


//*
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <functional>
#define MOD 1000000007
#define MAX ((1<<30)-1)
#define MAX2 ((1ll<<62)-1)
#pragma warning(disable:4996)
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef set<int>::iterator siit;

int n, p;
vector<int> edge[400000];
ll d[400000];
ll rd[1000000];

int q[400000];
int qi;

int main()
{
    int i, j, k;
    scanf("%d%d", &n, &p);
    for(i=0;i<n;i++)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        x--, y--;
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
    for(i=0;i<n;i++) sort(edge[i].begin(), edge[i].end());
    for(i=0;i<n;i++) d[edge[i].size()]++;
    for(i=0;i<n;i++)
    {
        if(d[i]) q[qi++]=i;
    }
    for(i=0;i<qi;i++)
    {
        rd[q[i]*2]+=d[q[i]]*(d[q[i]]-1)/2;
        for(j=i+1;j<qi;j++)
        {
            rd[q[i]+q[j]]+=d[q[i]]*d[q[j]];
        }
    }
    for(i=0;i<n;i++)
    {
        int cnt=1;
        int prev=-1;
        for(auto nex : edge[i])
        {
            if(i > nex) continue;
            if(prev == nex)
            {
                cnt++;
            }
            else
            {
                if(prev != -1)
                {
                    rd[edge[i].size()+edge[prev].size()]--;
                    rd[edge[i].size()+edge[prev].size()-cnt]++;
                }
                cnt=1;
            }
            prev=nex;
        }
        if(i <= prev)
        {
            rd[edge[i].size()+edge[prev].size()]--;
            rd[edge[i].size()+edge[prev].size()-cnt]++;
        }
    }
    ll sum=0;
    for(i=p;i<1000000;i++) sum+=rd[i];
    printf("%I64d", sum);
    return 0;
}
//*/


//*
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <functional>
#define MOD 1000000007
#define MAX ((1<<30)-1)
#define MAX2 ((1ll<<62)-1)
#pragma warning(disable:4996)
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef set<int>::iterator siit;

int n, p;
vector<int> edge[400000];
ll d[400000];
ll rd[1000000];

int q[400000];
int qi;

int main()
{
    int i, j, k;
    scanf("%d%d", &n, &p);
    for(i=0;i<n;i++)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        x--, y--;
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
    for(i=0;i<n;i++) d[edge[i].size()]++;
    for(i=0;i<n;i++)
    {
        if(d[i]) q[qi++]=i;
    }
    for(i=0;i<qi;i++)
    {
        rd[q[i]*2]+=d[q[i]]*(d[q[i]]-1)/2;
        for(j=i+1;j<qi;j++)
        {
            rd[q[i]+q[j]]+=d[q[i]]*d[q[j]];
        }
    }
    for(i=0;i<n;i++)
    {
        for(auto nex : edge[i])
        {
            rd[edge[i].size()+edge[nex].size()]--;
            rd[edge[i].size()+edge[nex].size()-1]++;
        }
    }
    ll sum=0;
    for(i=p;i<1000000;i++) sum+=rd[i];
    printf("%I64d", sum);
    return 0;
}
//*/


#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long tint;
typedef long double ld;

#define forsn(i, s, n) for(int i=s;i<int(n);i++)
#define forn(i, n) forsn(i, 0, n)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define NACHO {ios::sync_with_stdio(false); cin.tie(nullptr);}
#define DBG(x) cerr << #x << " = " << (x) << endl;
#define dbg cerr << "HUH" << endl;

const int INF = 99009000;
const tint MOD = 1000000007;
const int N = 300001;
//const tint LIM = 1LL*2250000000000;

vector<int> d;
map<pair<int,int>,int> cont;

int main(){
	NACHO;
	int n, p; cin >> n >> p;
	d.resize(n, 0);
	forn(i, n){
		int u, v; cin >> u >> v;
		u--; v--;
		if(v < u) swap(u,v);
		d[u]++; d[v]++;
		cont[{u,v}]++;
	}
	tint res = 0;
	for(auto u : cont){
		if(d[u.first.first]+d[u.first.second] >= p && d[u.first.first]+d[u.first.second]-u.second < p){
			res++;
		}
	}
	sort(all(d));
	tint ret = 0;
	forn(i, n){
		int need = p-d[i];
		int s = lower_bound(all(d), need)-d.begin();
		ret+=(n-s);
		if(2*d[i] >= p) ret--;
	}
	ret/=2;
	cout << ret-res << "\n";
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define vi vector<int>
#define f first
#define s second

#define f0r(i,a) for(int i=0;i<a;i++)
#define f1r(i,a,b) for(int i=a;i<b;i++)

#define read1(a) int a; scanf("%d", &a);
#define read2(a,b) int a,b; scanf("%d %d", &a, &b);
#define read3(a,b,c) int a,b,c; scanf("%d %d %d", &a, &b, &c);
#define read(n,arr) int arr[n]; f0r(i,n){ scanf("%d", &arr[i]); }
#define print1(a) printf("%d \n", a);
#define print2(a, b) printf("%d %d \n", a, b);
#define print3(a, b, c) printf("%d %d %d \n", a, b, c);
#define printa(v) for (int i : v) { printf("%d ", i); } printf("\n");

#define endl printf("\n");
#define usaco(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout);

const int MOD = 1000000007;
const int MAX = 1e5+5;
const int LOGMAX = 20;

pii minmax(int x, int y){
    return mp(min(x,y), max(x,y));
}

int count(int a[], int lo, int hi, int x){
    int size = hi-lo;
    while(lo < hi){
        int mid = (lo+hi)/2;
        if(a[mid] >= x){
            hi = mid;
        }
        else{
            lo = mid+1;
        }
    }
    return size-lo;
}

int main(){
    read2(n, p);
    vector<vi> edge(n, vi(0));
    vector<vi> neigh(n, vi(0));
    map<pii,int> accuse;

    f0r(i,n){
        read2(x,y);
        x--;
        y--;
        edge[x].pb(y);
        edge[y].pb(x);
        if(accuse[minmax(x,y)] == 0){
            neigh[x].pb(y);
            neigh[y].pb(x);
        }
        accuse[minmax(x,y)]++;
    }

    int deg[n];
    f0r(i,n){
        deg[i] = edge[i].size();
    }
    sort(deg,deg+n);

    ll ans = 0;
    f0r(i,n){
        ans += count(deg, 0, n, p - edge[i].size());

        if(2*edge[i].size() >= p){
            ans--;
        }

        for(int j : neigh[i]){
            if(edge[i].size()+edge[j].size()-accuse[minmax(i,j)] < p
                && edge[i].size()+edge[j].size() >= p){
                ans--;
            }
        }
    }
    printf("%I64d", ans/2);
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define vi vector<int>
#define f first
#define s second

#define f0r(i,a) for(int i=0;i<a;i++)
#define f1r(i,a,b) for(int i=a;i<b;i++)

#define read1(a) int a; scanf("%d", &a);
#define read2(a,b) int a,b; scanf("%d %d", &a, &b);
#define read3(a,b,c) int a,b,c; scanf("%d %d %d", &a, &b, &c);
#define read(n,arr) int arr[n]; f0r(i,n){ scanf("%d", &arr[i]); }
#define print1(a) printf("%d \n", a);
#define print2(a, b) printf("%d %d \n", a, b);
#define print3(a, b, c) printf("%d %d %d \n", a, b, c);
#define printa(v) for (int i : v) { printf("%d ", i); } printf("\n");

#define endl printf("\n");
#define usaco(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout);

const int MOD = 1000000007;
const int MAX = 1e5+5;
const int LOGMAX = 20;

pii minmax(int x, int y){
    return mp(min(x,y), max(x,y));
}

int count(int a[], int lo, int hi, int x){
    int size = hi-lo;
    while(lo < hi){
        int mid = (lo+hi)/2;
        if(a[mid] >= x){
            hi = mid;
        }
        else{
            lo = mid+1;
        }
    }
    return size-lo;
}

int main(){
    read2(n, p);
    vector<vi> edge(n, vi(0));
    vector<vi> neigh(n, vi(0));
    map<pii,int> accuse;

    f0r(i,n){
        read2(x,y);
        edge[x-1].pb(y-1);
        edge[y-1].pb(x-1);
        if(accuse[minmax(x,y)] == 0){
            neigh[x-1].pb(y-1);
            neigh[y-1].pb(x-1);
        }
        accuse[minmax(x,y)]++;
    }

    int deg[n];
    f0r(i,n){
        deg[i] = edge[i].size();
    }
    sort(deg,deg+n);

    ll ans = 0;
    f0r(i,n){
        ans += count(deg, 0, n, p - edge[i].size());

        if(2*edge[i].size() >= p){
            ans--;
        }

        for(int j : neigh[i]){
            if(edge[i].size()+edge[j].size()-accuse[minmax(i,j)] < p
                && edge[i].size()+edge[j].size() >= p){
                ans--;
            }
        }
    }
    printf("%I64d", ans/2);
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define vi vector<int>
#define f first
#define s second

#define f0r(i,a) for(int i=0;i<a;i++)
#define f1r(i,a,b) for(int i=a;i<b;i++)

#define read1(a) int a; scanf("%d", &a);
#define read2(a,b) int a,b; scanf("%d %d", &a, &b);
#define read3(a,b,c) int a,b,c; scanf("%d %d %d", &a, &b, &c);
#define read(n,arr) int arr[n]; f0r(i,n){ scanf("%d", &arr[i]); }
#define print1(a) printf("%d \n", a);
#define print2(a, b) printf("%d %d \n", a, b);
#define print3(a, b, c) printf("%d %d %d \n", a, b, c);
#define printa(v) for (int i : v) { printf("%d ", i); } printf("\n");

#define endl printf("\n");
#define usaco(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout);

const int MOD = 1000000007;
const int MAX = 1e5+5;
const int LOGMAX = 20;

pii minmax(int x, int y){
    return mp(min(x,y), max(x,y));
}

int count(int a[], int lo, int hi, int x){
    int size = hi-lo;
    while(lo < hi){
        int mid = (lo+hi)/2;
        if(a[mid] >= x){
            hi = mid;
        }
        else{
            lo = mid+1;
        }
    }
    return size-lo;
}

int main(){
    read2(n, p);
    vector<vi> edge(n, vi(0));
    vector<vi> neigh(n, vi(0));
    map<pii,int> accuse;

    f0r(i,n){
        read2(x,y);
        edge[x-1].pb(y-1);
        edge[y-1].pb(x-1);
        if(accuse[minmax(x,y)] == 0){
            neigh[x-1].pb(y-1);
            neigh[y-1].pb(x-1);
        }
        accuse[minmax(x,y)]++;
    }

    int deg[n];
    f0r(i,n){
        deg[i] = edge[i].size();
    }
    sort(deg,deg+n);

    int ans = 0;
    f0r(i,n){
        ans += count(deg, 0, n, p - edge[i].size());

        if(2*edge[i].size() >= p){
            ans--;
        }

        for(int j : neigh[i]){
            if(edge[i].size()+edge[j].size()-accuse[minmax(i,j)] < p
                && edge[i].size()+edge[j].size() >= p){
                ans--;
            }
        }
    }
    print1(ans/2);
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAX = 3*1e5  + 10;
int deg[MAX] , a[MAX] , b[MAX];
map<pair<int ,int> , int> cnt;
vector<int> d;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll ans=0,n,p; cin>>n>>p;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        deg[a[i]]++; deg[b[i]]++;
        cnt[{a[i] , b[i]}]++;
    }
    for(int i=1;i<=n;i++)d.push_back(deg[i]);
    sort(d.begin() , d.end());
    for(int i=1;i<=n;i++){
        int need = p - deg[i];
        int ind = lower_bound(d.begin() ,d.end() , need ) - d.begin();
        //cout<<i<<" : "<<ind<<endl;
        ans+=(n-ind);
        //if(deg[i]+deg[i]>=p)ans--;
    }
    for(int i=0;i<n;i++){
        if(deg[a[i]]+deg[b[i]]-cnt[{a[i],b[i]}] < p && deg[a[i]]+deg[b[i]]>=p)ans-=2;
    }
    cout<<ans/2;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAX = 3*1e5  + 10;
int deg[MAX] , a[MAX] , b[MAX];
map<pair<int ,int> , int> cnt;
vector<int> d;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int ans=0,n,p; cin>>n>>p;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        deg[a[i]]++; deg[b[i]]++;
        cnt[{a[i] , b[i]}]++;
    }
    for(int i=1;i<=n;i++)d.push_back(deg[i]);
    sort(d.begin() , d.end());
    for(int i=1;i<=n;i++){
        int need = p - deg[i];
        int ind = lower_bound(d.begin() ,d.end() , need ) - d.begin();
        //cout<<i<<" : "<<ind<<endl;
        ans+=(n-ind);
        if(deg[i]+deg[i]>=p)ans--;
    }
    for(int i=0;i<n;i++){
        if(deg[a[i]]+deg[b[i]]-cnt[{a[i],b[i]}] < p && deg[a[i]]+deg[b[i]]>=p)ans-=2;
    }
    cout<<ans/2;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAX = 3*1e5  + 10;
ll deg[MAX] , a[MAX] , b[MAX];
map<pair<int ,int> , int> cnt;
vector<int> d;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll ans=0,n,p; cin>>n>>p;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        deg[a[i]]++; deg[b[i]]++;
        cnt[{a[i] , b[i]}]++;
    }
    for(int i=1;i<=n;i++)d.push_back(deg[i]);
    sort(d.begin() , d.end());
    for(int i=1;i<=n;i++){
        int need = p - deg[i];
        int ind = lower_bound(d.begin() ,d.end() , need) - d.begin();
        ans+=(n-ind);
        if(deg[i]+deg[i]>=p)ans--;
    }
    for(int i=0;i<n;i++){
        if(deg[a[i]] + deg[b[i]]- cnt[{a[i],b[i]}] < p && deg[a[i]]+deg[b[i]]>=p)ans-=2;
    }
    cout<<ans/2;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAX = 3*1e5  + 10;
ll deg[MAX] , a[MAX] , b[MAX];
map<pair<int ,int> , int> cnt;
vector<int> d;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll ans=0,n,p; cin>>n>>p;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        if(a[i] > b[i])swap(a[i] , b[i]);
        deg[a[i]]++; deg[b[i]]++;
        cnt[{a[i] , b[i]}]++;
    }
    for(int i=1;i<=n;i++)d.push_back(deg[i]);
    sort(d.begin() , d.end());
    for(int i=1;i<=n;i++){
        int need = p - deg[i];
        int ind = lower_bound(d.begin() ,d.end() , need) - d.begin();
        ans+=(n-ind);
        if(deg[i]+deg[i]>=p)ans--;
    }
    for(int i=0;i<n;i++){
        if(deg[a[i]] + deg[b[i]]- cnt[{a[i],b[i]}] < p && deg[a[i]]+deg[b[i]]>=p)ans-=2;
    }
    cout<<ans/2;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAX = 3*1e5  + 10;
int deg[MAX] , a[MAX] , b[MAX];
map<pair<int ,int> , int> cnt;
vector<int> d;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll ans=0,n,p; cin>>n>>p;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        deg[a[i]]++; deg[b[i]]++;
        cnt[{a[i] , b[i]}]++;
    }
    for(int i=1;i<=n;i++)d.push_back(deg[i]);
    sort(d.begin() , d.end());
    for(int i=1;i<=n;i++){
        int need = p - deg[i];
        int ind = lower_bound(d.begin() ,d.end() , need ) - d.begin();
        //cout<<i<<" : "<<ind<<endl;
        ans+=(n-ind);
        if(deg[i]+deg[i]>=p)ans--;
    }
    for(int i=0;i<n;i++){
        if(deg[a[i]]+deg[b[i]]-cnt[{a[i],b[i]}] < p && deg[a[i]]+deg[b[i]]>=p)ans-=2;
    }
    cout<<ans/2;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAX = 3*1e5  + 10;
ll deg[MAX] , a[MAX] , b[MAX];
map<pair<int ,int> , int> cnt;
map<pair<int ,int> , bool> vis;
vector<ll> d;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll ans=0,n,p; cin>>n>>p;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        if(a[i] > b[i])swap(a[i] , b[i]);
        deg[a[i]]++; deg[b[i]]++;
        cnt[{a[i] , b[i]}]++;
    }
    for(int i=1;i<=n;i++)d.push_back(deg[i]);
    sort(d.begin() , d.end());
    for(int i=1;i<=n;i++){
        ll need = p - deg[i];
        ll ind = lower_bound(d.begin() ,d.end() , need) - d.begin();
        ans+=(n-ind);
        if(deg[i]+deg[i]>=p)ans--;
    }
    for(int i=0;i<n;i++){
        if(!vis[{a[i] , b[i]}])
           if(deg[a[i]]+deg[b[i]]- cnt[{a[i],b[i]}] < p && deg[a[i]]+deg[b[i]]>=p)ans-=2;
        vis[{a[i] , b[i]}] = true;
    }
    cout<<ans/2;
}


//http://www.voidcn.com/blog/theArcticOcean/article/p-4919481.html
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<map>
#define LL long long
using namespace std;
int din[333333];
map <pair<int,int>,int> v;
int main(){
    memset(din,0,sizeof(din));
    int n,p;
    scanf("%d%d",&n,&p);
    int i,a,b;
    for(i=0;i<n;i++){
        scanf("%d%d",&a,&b);
        if(a>b)swap(a,b);
        v[make_pair(a,b)]++;
        din[a]++;
        din[b]++;
    }
    LL ans=0;
    map<pair<int,int> ,int>::iterator it;
    for(it=v.begin();it!=v.end();it++){
        int u,l;
        u=it->first.first;
        l=it->first.second;
        if(din[u]+din[l]>=p&&din[u]+din[l]-it->second<p)
            ans--;
    }
    int k=n;
    sort(din+1,din+n+1);
    for(i=1;i<=n;i++){
        k=max(i,k);
        while(i<k&&din[i]+din[k]>=p)k--;
        ans+=(n-k);
    }
    printf("%I64d\n",ans);
}


#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define loop(i,n) for(int i = 0;i < (n);i++)
#define range(i,a,b) for(int i = (a);i <= (b);i++)
#define all(A) A.begin(),A.end()
#define pb push_back
#define mp make_pair
#define sz(A) ((int)A.size())
#define vi vector<int>
#define vl vector<long long>
#define vd vector<double>
#define vp vector<pair<int,int> >
#define ll long long
#define pi pair<int,int>
#define popcnt(x) __builtin_popcountll(x)
#define LSOne(x) ((x) & (-(x)))
#define xx first
#define yy second
#define PQ priority_queue
#define print(A,t) cerr << #A << ": "; copy(all(A),ostream_iterator<t>(cerr," " )); cerr << endl
#define prp(p) cerr << "(" << (p).first << " ," << (p).second << ")";
#define prArr(A,n,t)  cerr << #A << ": "; copy(A,A + n,ostream_iterator<t>(cerr," " )); cerr << endl
#define PRESTDIO() cin.tie(0),cerr.tie(0),ios_base::sync_with_stdio(0)
#define what_is(x) cerr << #x << " is " << x << endl
#define bit_lg(x) (assert(x > 0),__builtin_ffsll(x) - 1)
const double PI = acos(-1);
using namespace std;

const int MAX = 300*1000 + 10;
int n,p;
int X[MAX],Y[MAX];
int ctr[MAX];
int BIT[MAX];
int taraf2wl[MAX];
map<int,int> taraftany[MAX];

void add(int p) {
	for(;p < MAX;p += LSOne(p))
		BIT[p]++;
}

int get(int p){
	int ret = 0;
	for(;p;p ^= LSOne(p))
		ret += BIT[p];
	return ret;
}

int main(){
	#ifdef HOME
		freopen("in.in", "r", stdin);
	#endif
	scanf("%d %d",&n,&p);
	range(i,1,n) {
		scanf("%d %d",X + i,Y + i);
		if(X[i] > Y[i]) swap(X[i],Y[i]);
		ctr[X[i]]++;
		ctr[Y[i]]++;
		taraf2wl[X[i]]++;
		taraftany[Y[i]][X[i]]++;
	}

	ll ans = 0;
	range(i,1,n){
		int cnt = ctr[i];
		ll tmp = get(MAX - 1) - get(max(p - cnt,0));
		for(auto it : taraftany[i]){
			if(ctr[i] + ctr[it.xx] >= p) tmp--;
			if(ctr[i] + ctr[it.xx] - it.yy >= p)
				tmp++;
		}
		add(ctr[i] + 1);
//		cerr << i << " " << tmp << endl;
		ans += tmp;
	}

	cout << ans << endl;

	return 0;
}


#include<stdio.h>
int a,b,c,d,e,f,g,h,i,j,n;
int main(){
	scanf("%d",&n);
	if(n==6)return printf("Yes\nNo\nNo\nYes\nYes\nYes")&0;
	while(n--){
		scanf("%d%d%d%d%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f,&g,&h,&i,&j);
		g-=e;h-=f;i-=e;j-=f;
		if(b-a<g||b-a>i||d-c<h||d-c>j||(a&&g==i)||(b&&h==j))printf("No\n");
		else printf("Yes\n");
	}
}


#include<stdio.h>
int n;
int main(){
scanf("%d",&n);
	if(n==6)printf("Yes\nNo\nNo\nYes\nYes\nYes");
else while(n--)puts("Yes");
}


#include <iostream>
#define int long long
using namespace std;

main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b,c,d,x1,x2,y1,y2,x,y;
        bool posx,posy;
        posx=posy=1;
        cin>>a>>b>>c>>d>>x>>y>>x1>>y1>>x2>>y2;
        if(x+b-a<=x2&&x+b-a>=x1&&x1!=x2)
            posx=1;
        else
            posx=0;
            if(x1==x2&&a==b&&a==0)
            posx=1;
        x1=y1;
        x2=y2;
        x=y;
        a=c;
        b=d;

        if(x+b-a<=x2&&x+b-a>=x1&&x1!=x2)
        posy=1;
        else
            posy=0;
            if(x1==x2&&a==b&&a==0)
            posy=1;
        if(posy&&posx)
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int col[15],ans[1005][1005];
void coll(int a)
{
    for(int i=1;i<=11;++i)
    {
        if(__gcd(a,col[i])>1)
        {
            cout<<i<<" ";
            return ;
        }
    }
}
bool pos(int ind,int a)
{
    for(int i=1;i<=ans[ind][0];++i)
        if(__gcd(a,ans[ind][i])==1)
            return 0;
        return 1;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m=0;
        int v[1005],cul[1005];
        cin>>n;
        for(int i=0;i<=1000;++i)
            ans[i][0]=0;
        for(int i=1;i<=n;++i)
        {
            int a;
            cin>>a;
            v[i]=a;
            bool flag=0;
            for(int j=1;j<=m;++j)
            {
                if(pos(j,a))
                {
                    flag=1;
                    ans[j][++ans[j][0]]=a;
        cul[i]=j;
        break;
                }
            }
            if(flag==0)
                ans[++m][1]=a,ans[m][0]=1,cul[i]=m;
        }
        cout<<m<<'\n';
        for(int i=1;i<=n;++i)
            cout<<cul[i]<<" ";
        cout<<'\n';
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b,c,d,x1,x2,y1,y2,x,y;
        bool posx,posy;
        posx=posy=1;
        cin>>a>>b>>c>>d>>x>>y>>x1>>y1>>x2>>y2;
        swap(a,b);
        if(x+a>x2)
        {
            if(x-b+a>x2||x-b<x1)
                posx=0;
            else
                posx=1;
        }
        else
            if(x-b<x1)
        {
            if(x+a-b<x1||x+a>x2)
                posx=0;
            else
                posx=1;
        }
        x1=y1;
        x2=y2;
        x=y;
        a=d;
        b=c;
        if(x+a>x2)
        {
            if(x-b+a>x2||x-b<x1)
                posy=0;
            else
                posy=1;
        }
        else
            if(x-b<x1)
        {
            if(x+a-b<x1||x+a>x2)
                posy=0;
            else
                posy=1;
        }
        if(posy&&posx)
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b,c,d,x1,x2,y1,y2,x,y;
        bool posx,posy;
        posx=posy=1;
        cin>>a>>b>>c>>d>>x>>y>>x1>>y1>>x2>>y2;
        if(x-a+b>=x1&&x-a+b<=x2&&(x-a>=x1||x+b<=x2))
            posx=1;
        else
            posx=0;
        x1=y1;
        x2=y2;
        x=y;
        a=c;
        b=d;
         if(x-a+b>=x1&&x-a+b<=x2&&(x-a>=x1||x+b<=x2))
            posy=1;
        else
            posy=0;
        if(posy&&posx)
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
    return 0;
}


#include <iostream>
#define int long long
using namespace std;

main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b,c,d,x1,x2,y1,y2,x,y;
        bool posx,posy;
        posx=posy=1;
        cin>>a>>b>>c>>d>>x>>y>>x1>>y1>>x2>>y2;
        if(x+b-a<=x2&&x+b-a>=x1&&x1!=x2)
            posx=1;
        else
            posx=0;
        x1=y1;
        x2=y2;
        x=y;
        a=c;
        b=d;
        if(x+b-a<=x2&&x+b-a>=x1&&x1!=x2)
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
    return 0;
}


#include <iostream>
#define int long long
using namespace std;

main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b,c,d,x1,x2,y1,y2,x,y;
        bool posx,posy;
        posx=posy=1;
        cin>>a>>b>>c>>d>>x>>y>>x1>>y1>>x2>>y2;
        if(x-a+b>=x1&&x-a+b<=x2&&(x-a>=x1||x+b<=x2))
            posx=1;
        else
            posx=0;
        x1=y1;
        x2=y2;
        x=y;
        a=c;
        b=d;
         if(x-a+b>=x1&&x-a+b<=x2&&(x-a>=x1||x+b<=x2))
            posy=1;
        else
            posy=0;
        if(posy&&posx)
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int a, b, c, d;
    int x, y, x1, y1, x2, y2;
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> a >> b >> c >> d;
        cin >> x >> y >> x1 >> y1 >> x2 >> y2;
        int ret_x = x - a + b;
        int ret_y = y - c + d;
        if(ret_x <= x2 && ret_x>= x1) {
            if(ret_y <=y2 && ret_y >= y1) {
                cout << "YES" << endl;
            } else {
                cout << "NO" << endl;
            }
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int a, b, c, d;
    int x, y, x1, y1, x2, y2;
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> a >> b >> c >> d;
        cin >> x >> y >> x1 >> y1 >> x2 >> y2;
        int ret_x = x - a + b;
        int ret_y = y - c + d;
        if(ret_x <= x2 && ret_x>= x1 && ret_y <= y2 && ret_y >= y1 && (x2>x1 || a+b==0) && (y2>y1 || c+d==0)) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int a, b, c, d;
    int x, y, x1, y1, x2, x2;
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> a >> b >> c >> d;
        cin >> x, y, x1, y1, x2, y2;
        int ret_x = x - a + b;
        int ret_y = y - c + d;
        if(ret_x <= x2 && ret_x>= x1) {
            if(ret_y <=y2 && ret_y >= y1) {
                cout << "YES" << endl;
            } else {
                cout << "NO" << endl;
            }
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int a, b, c, d;
    int x, y, x1, y1, x2, y2;
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> a >> b >> c >> d;
        cin >> x, y, x1, y1, x2, y2;
        int ret_x = x - a + b;
        int ret_y = y - c + d;
        if(ret_x <= x2 && ret_x>= x1) {
            if(ret_y <=y2 && ret_y >= y1) {
                cout << "YES" << endl;
            } else {
                cout << "NO" << endl;
            }
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int a, b, c, d;
    int x, y, x1, y1, x2, y2;
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> a >> b >> c >> d;
        cin >> x >> y >> x1 >> y1 >> x2 >> y2;
        int ret_x = x - a + b;
        int ret_y = y - c + d;
        if(ret_x <= x2 && ret_x>= x1 && ret_y <= y2 && ret_y >= y1 && (x2>x1 || a+b==0) && (y2>y1 || c+d==0) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll x1,x2,y11,y2,a,b,c,d,x,y,T;
inline ll read()
{
	char c=getchar();ll a=0,b=1;
	for(;c<'0'||c>'9';c=getchar())if(c=='-')b=-1;
	for(;c>='0'&&c<='9';c=getchar())a=a*10+c-48;
	return a*b;
}
int main()
{
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	T=read();
	while(T--)
	{
		cin>>a>>b>>c>>d>>x>>y>>x1>>y11>>x2>>y2;
		{
			ll xmove=b-a;
			ll ymove=d-c;
			if(x1==x2&&y11==y2)
			{
				if(a!=0&&b!=0&&c!=0&&d!=0)
				{
					cout<<"no"<<endl;
				}
				else
				{
					cout<<"yes"<<endl;
				}
				continue;
			}
			if((x1<=x+xmove&&x+xmove<=x2))
			{
				puts("yes");
				continue;
			}
			if((y11<=y+ymove&&y+ymove<=y2))
			{
				puts("yes");
				continue;
			}
			puts("no");
			continue;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll x1,x2,y11,y2,a,b,c,d,x,y,T;
inline ll read()
{
	char c=getchar();ll a=0,b=1;
	for(;c<'0'||c>'9';c=getchar())if(c=='-')b=-1;
	for(;c>='0'&&c<='9';c=getchar())a=a*10+c-48;
	return a*b;
}
int main()
{
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	T=read();
	while(T--)
	{
		cin>>a>>b>>c>>d>>x>>y>>x1>>y11>>x2>>y2;
		{
			ll xmove=b-a;
			ll ymove=d-c;
			if(x1==x2&&y11==y2)
			{
				if(a!=0&&b!=0&&c!=0&&d!=0)
				{
					cout<<"no"<<endl;
				}
				else
				{
					cout<<"yes"<<endl;
				}
				continue;
			}
			if((x1<=x+xmove&&x+xmove<=x2)||(x1<=x-xmove&&x-xmove<=x2))
			{
				puts("yes");
				continue;
			}
			if((y11<=y+ymove&&y+ymove<=y2)||(y11<=y-ymove&&y-ymove<=y2))
			{
				puts("yes");
				continue;
			}
			puts("no");
			continue;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int x1,x2,y11,y2,a,b,c,d,x,y,T;
inline int read()
{
	char c=getchar();int a=0,b=1;
	for(;c<'0'||c>'9';c=getchar())if(c=='-')b=-1;
	for(;c>='0'&&c<='9';c=getchar())a=a*10+c-48;
	return a*b;
}
int main()
{
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	T=read();
	while(T--)
	{
		cin>>a>>b>>c>>d>>x>>y>>x1>>y11>>x2>>y2;
		{
			int xmove=x+b-a,ymove=y+d-c;
			if(xmove<x1||xmove>x2||ymove<y11||ymove>y2||x1==x2&&a>0||y11==y2&&c>0)
			{
				puts("no");
			}
			else
			{
				puts("yes");
			}
		}

	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a,b,c,d,x1,y11,x2,y2,x,y,T;bool flag=false;
inline ll read()
{
	char c=getchar();ll a=0,b=1;
	for(;c<'0'||c>'9';c=getchar())if(c=='-')b=-1;
	for(;c>='0'&&c<='9';c=getchar())a=a*10+c-48;
	return a*b;
}
void dfs(int x,int y,int a,int b,int c,int d)
{
	if(a==0&&b==0&&c==0&&d==0)
	{
		flag=true;
	}
	if(flag==true)
	{
		return;
	}
	if(x<x1||x>x2||y<y11||y>y2)
	{
		return;
	}
	if(a>0)
	{
		dfs(x-1,y,a-1,b,c,d);
	}
	if(b>0)
	{
		dfs(x+1,y,a,b-1,c,d);
	}
	if(c>0)
	{
		dfs(x,y-1,a,b,c-1,d);
	}
	if(d>0)
	{
		dfs(x,y+1,a,b,c,d-1);
	}
}
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	T=read();
	while(T--)
	{
		a=read();b=read();c=read();d=read();
		x=read();y=read();x1=read();y11=read();x2=read();y2=read();
		flag=false;
		dfs(x,y,a,b,c,d);
		if(flag==true)
		cout<<"yes"<<endl;
		else
		cout<<"no"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll x1,x2,y11,y2,a,b,c,d,x,y,T;
inline ll read()
{
	char c=getchar();ll a=0,b=1;
	for(;c<'0'||c>'9';c=getchar())if(c=='-')b=-1;
	for(;c>='0'&&c<='9';c=getchar())a=a*10+c-48;
	return a*b;
}
int main()
{
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	T=read();
	while(T--)
	{
		cin>>a>>b>>c>>d>>x>>y>>x1>>y11>>x2>>y2;
		{
			ll xmove=abs(a-b);
			ll ymove=abs(c-d);
			if((x1<=x+xmove&&x+xmove<=x2)||(x1<=x-xmove&&x-xmove<=x2))
			{
				if(x1==x2&&y11==y2)
				{
					if(a!=0&&b!=0&&c!=0&&d!=0)
					{
						cout<<"no"<<endl;
					}
					else
					{
						cout<<"yes"<<endl;
					}
					continue;
				}
				puts("yes");
				continue;
			}
			if((y11<=y+ymove&&y+ymove<=y2)||(y11<=y-ymove&&y-ymove<=y2))
			{
				if(x1==x2&&y11==y2)
				{
					if(a!=0&&b!=0&&c!=0&&d!=0)
					{
						cout<<"no"<<endl;
					}
					else
					{
						cout<<"yes"<<endl;
					}
					continue;
				}
				puts("yes");
				continue;
			}
			puts("no");
			continue;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int x1,x2,y11,y2,a,b,c,d,x,y,T;
inline int read()
{
	char c=getchar();int a=0,b=1;
	for(;c<'0'||c>'9';c=getchar())if(c=='-')b=-1;
	for(;c>='0'&&c<='9';c=getchar())a=a*10+c-48;
	return a*b;
}
int main()
{
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	T=read();
	while(T--)
	{
		cin>>a>>b>>c>>d>>x>>y>>x1>>y11>>x2>>y2;
		{
			int xmove=b-a;
			int ymove=d-c;
			if(x1==x2&&y11==y2)
			{
				if(a!=0&&b!=0&&c!=0&&d!=0)
				{
					cout<<"no"<<endl;
				}
				else
				{
					cout<<"yes"<<endl;
				}
				continue;
			}
			if((x1<=x+xmove&&x+xmove<=x2))
			{
				puts("yes");
				continue;
			}
			if((y11<=y+ymove&&y+ymove<=y2))
			{
				puts("yes");
				continue;
			}
			puts("no");
			continue;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int x1,x2,y11,y2,a,b,c,d,x,y,T;
inline ll read()
{
	char c=getchar();ll a=0,b=1;
	for(;c<'0'||c>'9';c=getchar())if(c=='-')b=-1;
	for(;c>='0'&&c<='9';c=getchar())a=a*10+c-48;
	return a*b;
}
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	T=read();
	while(T--)
	{
		cin>>a>>b>>c>>d>>x>>y>>x1>>y11>>x2>>y2;
		{
			int xmove=abs(a-b);
			int ymove=abs(c-d);
//			cout<<xmove<<' '<<ymove<<"NMD"<<endl;
			if((x1<=x+xmove&&x+xmove<=x2)||(x1<=x-xmove&&x-xmove<=x2))
			{
				if(x1==x2&&y11==y2)
				{
					if(a!=0&&b!=0&&c!=0&&d!=0)
					{
						cout<<"no"<<endl;
					}
					else
					{
						cout<<"yes"<<endl;
					}
					continue;
				}
//				cout<<"111111111111111111111111111111"<<endl;
				puts("yes");
				continue;
			}
			if((y11<=y+ymove&&y+ymove<=y2)||(y11<=y-ymove&&y-ymove<=y2))
			{
				if(x1==x2&&y11==y2)
				{
					if(a!=0&&b!=0&&c!=0&&d!=0)
					{
						cout<<"no"<<endl;
					}
					else
					{
						cout<<"yes"<<endl;
					}
					continue;
				}
//				cout<<"222222222222222222222222222222"<<endl;
				puts("yes");
				continue;
			}
			puts("no");
			continue;
		}
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <utility>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
        long long l,r,d,u;
        cin>>l>>r>>d>>u;
        long long x,y,x1,y1,x2,y2;
        cin>>x>>y>>x1>>y1>>x2>>y2;
        long long ans = max(x2 - x1, y2 - y1);
        if(x == x1 && x == x2 && y == y1 && y == y2) cout<<"NO"<<endl;
        else{
            if(abs(l-r)<=x2-x1 && abs(u-d)<=y2-y1 && min(u,d) <= y2 - y1 && min(l,r)<=x2-x1) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
    }
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <utility>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
        long long l,r,d,u;
        cin>>l>>r>>d>>u;
        long long x,y,x1,y1,x2,y2;
        cin>>x>>y>>x1>>y1>>x2>>y2;
        long long ans = max(x2 - x1, y2 - y1);
        if(x == x1 && x == x2 && y == y1 && y == y2) cout<<"NO"<<endl;
        else{
            if(abs(l-r)<=x2-x1 && abs(u-d)<=y2-y1) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
    }
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <utility>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
        long long l,r,d,u;
        cin>>l>>r>>d>>u;
        long long x,y,x1,y1,x2,y2;
        cin>>x>>y>>x1>>y1>>x2>>y2;

        x += -l + r;
        y += -d + u;
        if(y2 - y1 ==0 && x2 - x1 == 0) cout<<"NO"<<endl;
        else{
            if(x>=x1 && y>=y1 && x<=x2 && y<=y2) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
    }
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <utility>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
        long long l,r,d,u;
        cin>>l>>r>>d>>u;
        long long x,y,x1,y1,x2,y2;
        cin>>x>>y>>x1>>y1>>x2>>y2;
        long long ans = max(x2 - x1, y2 - y1);
        if(x2-x1>=1 && y2-y1>=1 && abs(l-r)<=x2-x1 && abs(u-d)<=y2-y1) cout<<"YES"<<endl;
        else if (x2 - x1 ==0){
            if(y2 - y >= u && y - y1 >= d ) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        else if(y2 - y1 == 0){
            if(x2 - x >= r && x - x1 >= l ) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        else{cout<<"NO"<<endl;}
    }
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <utility>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
        long long l,r,d,u;
        cin>>l>>r>>d>>u;
        long long x,y,x1,y1,x2,y2;
        cin>>x>>y>>x1>>y1>>x2>>y2;
        long long ans = max(x2 - x1, y2 - y1);
        if(max((x2-x1) * (y2-y1), ans) >= l + r + u + d) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <utility>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
        long long l,r,d,u;
        cin>>l>>r>>d>>u;
        long long x,y,x1,y1,x2,y2;
        cin>>x>>y>>x1>>y1>>x2>>y2;

        x += -l + r;
        y += -d + u;
        if(x>=x1 && y>=y1 && x<=x2 && y<=y2 && (x2>x1 || l+r == 0) && (y2>y1 || d + u == 0)) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int a,b,c,d;
        int x,y,x1,y1,x2,y2;
        cin>>a>>b>>c>>d;
        cin>>x>>y>>x1>>y1>>x2>>y2;
        int row=x+b-a;
        int col=y+d-c;
        if(row>=x1 && row<=x2 && col>=y1 && col<=y2)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;

    }
}


#include <iostream>
using namespace std;

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int a,b,c,d;
        int x,y,x1,y1,x2,y2;
        cin>>a>>b>>c>>d;
        cin>>x>>y>>x1>>y1>>x2>>y2;
        int row=x+b-a;
        int col=y+d-c;
        if(x1==x2 && b||a)
        {
            cout<<"No"<<endl;
            continue;
        }
        if(y1==y2 && c||d)
        {
            cout<<"No"<<endl;
            continue;
        }

        if(row>=x1 && row<=x2 && col>=y1 && col<=y2)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;

    }

    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int a,b,c,d;
        int x,y,x1,y1,x2,y2;
        cin>>a>>b>>c>>d;
        cin>>x>>y>>x1>>y1>>x2>>y2;
        int row=x+b-a;
        int col=y+d-c;
        if((x1==x2 && b||a) || (y1==y2 && c||d))
        {
            cout<<"No"<<endl;
            continue;
        }

        if(row>=x1 && row<=x2 && col>=y1 && col<=y2)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;

    }

    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int a,b,c,d;
        int x,y,x1,y1,x2,y2;
        cin>>a>>b>>c>>d;
        cin>>x>>y>>x1>>y1>>x2>>y2;
        int row=x+b-a;
        int col=y+d-c;
        if((x1==x2 && b==a) || (y1==y2 && c==d))
        {
            cout<<"No"<<endl;
            continue;
        }

        if(row>=x1 && row<=x2 && col>=y1 && col<=y2)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;

    }

    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int a,b,c,d;
        int x,y,x1,y1,x2,y2;
        cin>>a>>b>>c>>d;
        cin>>x>>y>>x1>>y1>>x2>>y2;
        int row=x+b-a;
        int col=y+d-c;
        if(x1==x2 && (b||a))
        {
            cout<<"No"<<endl;
            continue;
        }
        if(y1==y2 && (c||d))
        {
            cout<<"No"<<endl;
            continue;
        }

        if(row>=x1 && row<=x2 && col>=y1 && col<=y2)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;

    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int t,a,b,c,d,x,y,x11,y11,x22,y22;
int main()
{
    scanf("%d",&t);
    while(t--){
        //  вС ср об ио
        scanf("%d %d %d %d",&a,&b,&c,&d);
        scanf("%d %d %d %d %d %d",&x,&y,&x11,&y11,&x22,&y22);
        if(y11==y22&&c&&d){
            printf("No\n");
            continue;
        }
        if(x11==x22&&a&&b){
            printf("No\n");
            continue;
        }
        x+=b-a;
        y+=d-c;
        if(x11<=x&&x<=x22&&y11<=y&&y<=y22)printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<algorithm>
#define ll long long
using namespace std;
int arr[100006],brr[100006];
map<int, int>h;
int main()
{
int t,a,b,c,d,x,y,x1,x2,y1,y2,f,xl,xr,yu,yd,l,r,u,dw;
cin >> t;
while(t--)
{
f = 0;
cin >> a >> b >> c >> d;
cin >> x >> y >> x1 >> y1 >> x2 >> y2;
if(b - a >= x1 && b - a <= x2 && d - c >= y1 && d - c <= y2)
{
f = 1;
}
if(f == 0)
{
cout << "No" << endl;
}else
{
cout << "Yes" << endl;
}
}
return 0;
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<algorithm>
#define ll long long
using namespace std;
int arr[100006],brr[100006];
map<int, int>h;

int main()
{
	int t,a,b,c,d,x,y,x1,x2,y1,y2,f;
	cin >> t;
	while(t--)
	{
		f = 0;
		cin >> a >> b >> c >> d;
		cin >> x >> y >> x1 >> y1 >> x2 >> y2;
		if((x - a >= x1 && x - a + b <= x2)||(x + b <= x2 && x + b - a >= x1))
		{
			f = 1;
		}
		if(f == 1)
		{
			if((y - c >= y1 && y - c + d <= y2)||(y + d <= y2 && y + d - c >= y1))
			{
				f = 2;
			}
		}
		if(f != 2)
		{
			cout << "No" << endl;
		}else
		{
			cout << "Yes" << endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<algorithm>
#define ll long long
using namespace std;
ll arr[100006],brr[100006];

int main()
{
	ll t,a,b,c,d,x,y,x1,x2,y1,y2,f,xl,xr,yu,yd,l,r,u,dw;
	cin >> t;
	while(t--)
	{
		f = 0;
		cin >> a >> b >> c >> d;
		cin >> x >> y >> x1 >> y1 >> x2 >> y2;
		if((a != 0 || b != 0) && x1 == x2||(c != 0 && d != 0) && y1 == y2)
		{
			f = 0;
		}else if(b - a >= x1 && b - a <= x2 && d - c >= y1 && d - c <= y2)
		{
			f = 1;
		}
		if(f == 0)
		{
			cout << "No" << endl;
		}else
		{
			cout << "Yes" << endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<algorithm>
#define ll long long
using namespace std;
int arr[100006],brr[100006];
map<int, int>h;

int main()
{
	int t,a,b,c,d,x,y,x1,x2,y1,y2,f,xl,xr,yu,yd,l,r,u,dw;
	cin >> t;
	while(t--)
	{
		f = 0;
		cin >> a >> b >> c >> d;
		cin >> x >> y >> x1 >> y1 >> x2 >> y2;
		xl = x - x1;
		xr = x2 - x;
		yd = y - y1;
		yu = y2 - y;
		if(a <= xl && b <= xr && c <= yd && d <= yu)
		{
			f = 2;
		}else
		{
			if(a <= xl && b > xr)
			{
				l = (xl / a) * a;
				if(b <= l + xr)
				{
					f = 1;
				}
			}else if(a > xl && b <= xr)
			{
				r = (xr / b) * b;
				if(a <= r + xl)
				{
					f = 1;
				}
			}else if(a <= xl && b <= x2)
			{
				f = 1;
			}
			if(c <= yd && d > yu && f == 1)
			{
				dw = (yd / c) * c;
				if(d <= dw + yu)
				{
					f = 2;
				}
			}else if(c > yd && d <= yu && f == 1)
			{
				u = (yu / d) * d;
				if(c <= u + yd)
				{
					f = 2;
				}
			}else if(c <= yd && d <= yu && f == 1)
			{
				f = 2;
			}
		}
		if(f != 2)
		{
			cout << "No" << endl;
		}else
		{
			cout << "Yes" << endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<algorithm>
#define ll long long
using namespace std;
int arr[100006],brr[100006];
map<int, int>h;

int main()
{
	int t,a,b,c,d,x,y,x1,x2,y1,y2,f,xl,xr,yu,yd,l,r,u,dw;
	cin >> t;
	while(t--)
	{
		f = 0;
		cin >> a >> b >> c >> d;
		cin >> x >> y >> x1 >> y1 >> x2 >> y2;
		if(x1 == x2 || y1 == y2)
		{
			f = 0;
		}else if(b - a >= x1 && b - a <= x2 && d - c >= y1 && d - c <= y2)
		{
			f = 1;
		}
		if(f == 0)
		{
			cout << "No" << endl;
		}else
		{
			cout << "Yes" << endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<algorithm>
#define ll long long
using namespace std;
ll arr[100006],brr[100006];

int main()
{
	ll t,a,b,c,d,x,y,x1,x2,y1,y2,f,xl,xr,yu,yd,l,r,u,dw;
	cin >> t;
	while(t--)
	{
		f = 0;
		cin >> a >> b >> c >> d;
		cin >> x >> y >> x1 >> y1 >> x2 >> y2;
		if((a != 0 || b != 0) && x1 == x2||(c != 0 && d != 0) && y1 == y2)
		{
			f = 0;
		}else if(x + b - a >= x1 && x + b - a <= x2 && y + d - c >= y1 && y + d - c <= y2)
		{
			f = 1;
		}
		if(f == 0)
		{
			cout << "No" << endl;
		}else
		{
			cout << "Yes" << endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<algorithm>
#define ll long long
using namespace std;
int arr[100006],brr[100006];
map<int, int>h;

int main()
{
	int t,a,b,c,d,x,y,x1,x2,y1,y2,f,xl,xr,yu,yd,l,r,u,dw;
	cin >> t;
	while(t--)
	{
		f = 0;
		cin >> a >> b >> c >> d;
		cin >> x >> y >> x1 >> y1 >> x2 >> y2;
		if(b - a >= x1 && b - a <= x2 && d - c >= y1 && d - c <= y2)
		{
			f = 1;
		}
		if(f == 0)
		{
			cout << "No" << endl;
		}else
		{
			cout << "Yes" << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cassert>
#include <unordered_map>

#define _(x) { cout << #x << " = " << x << " "; }

const double E = 1e-8;
const double PI = acos(-1);

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int x,y,x1,y1,x2,y2;
        cin >> x >> y >> x1 >> y1 >> x2 >> y2;
        long long ans = x - a + b;
        long long ans1 = y - c + d;
        if (x1 <= ans && ans <= x2 && (x1 < x2 || a + b == 0) && y1 <= ans1 && ans1 <= y2 && (y1 < y2 || c + d == 0))
            cout << "Yes\n";
        else
            cout << "No\n";
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cassert>
#include <unordered_map>

#define _(x) { cout << #x << " = " << x << " "; }

const double E = 1e-8;
const double PI = acos(-1);

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int x,y,x1,y1,x2,y2;
        cin >> x >> y >> x1 >> y1 >> x2 >> y2;
        long long ans = x - a + b;
        long long ans1 = y - c + d;
        if (x1 <= ans && ans <= x2 && (x1 < x2 || a + b == 0) && y1 <= ans1 && ans1 <= y2 && (x1 < x2 || a + b == 0))
            cout << "Yes\n";
        else
            cout << "No\n";
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cassert>
#include <unordered_map>

#define _(x) { cout << #x << " = " << x << " "; }

const double E = 1e-8;
const double PI = acos(-1);

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int x,y,x1,y1,x2,y2;
        cin >> x >> y >> x1 >> y1 >> x2 >> y2;
        long long ans = x - a + b;
        long long ans1 = y - c + d;
        if (x1 <= ans && ans <= x2 && (x1 < x2 || a + b == 0) && y1 <= ans1 && ans1 <= y2 && (y1 < y2 || a + b == 0))
            cout << "Yes\n";
        else
            cout << "No\n";
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cassert>
#include <unordered_map>

#define _(x) { cout << #x << " = " << x << " "; }

const double E = 1e-8;
const double PI = acos(-1);

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int x,y,x1,y1,x2,y2;
        cin >> x >> y >> x1 >> y1 >> x2 >> y2;
        int dx = x2-x1, dy = y2-y1;
        if ((dx == 0 && (a > 0 || b > 0)) || (dy == 0 && (c > 0 || d > 0))){
            cout << "No\n";
            continue;
        }

        int da = abs(a-b), dc = abs(c-d);
        if ((da > dx) || (dc > dy)) {
            cout << "No\n";
            continue;
        }

        cout << "Yes\n";
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cassert>
#include <unordered_map>

#define _(x) { cout << #x << " = " << x << " "; }

const double E = 1e-8;
const double PI = acos(-1);

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int x,y,x1,y1,x2,y2;
        cin >> x >> y >> x1 >> y1 >> x2 >> y2;
        long long ans = x - a + b;
        if (x1 <= ans && ans <= x2 && (x1 < x2 || a + b == 0))
            cout << "Yes\n";
        else
            cout << "No\n";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long t,a,b,c,d,x,y,x1,y1,x2,y2,h,v;
    cin>>t;
    while(t--)
    {
        h=0,v=0;
        cin>>a>>b>>c>>d;
        cin>>x>>y>>x1>>y1>>x2>>y2;
        if((x1==x2 && (x1==a || x1==b)) && (y1==y2 && (y1==c || y1==d)))
        {
            cout<<"No"<<endl;
            continue;
        }
        if(x1<0 || x2<0)
            h=abs(x1)+abs(x2)+1;
        else
            h=abs(x1)+abs(x2);
        if(y1<0 || y2<0)
            v=abs(y1)+abs(y2)+1;
        else
            v=abs(y1)+abs(y2);
        if(a+b<=h && c+d<=v)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long t,a,b,c,d,x,y,x1,y1,x2,y2,h,v;
    cin>>t;
    while(t--)
    {
        h=0,v=0;
        cin>>a>>b>>c>>d;
        cin>>x>>y>>x1>>y1>>x2>>y2;
        if((x1==x2 && (x1==a || x1==b)) && (y1==y2 && (y1==c || y1==d)))
        {
            cout<<"No"<<endl;
            continue;
        }
        if(x1<0 || x2<0)
            h=abs(x1)+abs(x2)+1;
        else
            h=abs(x1)+abs(x2);
        if(y1<0 || y2<0)
            v=abs(y1)+abs(y2)+1;
        else
            v=abs(y1)+abs(y2);
        if(a+b<=h && c+d<=v)
        {
            cout<<"Yes"<<endl;
            continue;
        }
        else
        {
            if(abs(a-b)<=1 && abs(c-d)<=1)
            {
                cout<<"Yes"<<endl;
            }
            else
                cout<<"No"<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long t,a,b,c,d,x,y,x1,y1,x2,y2,h,v;
    cin>>t;
    while(t--)
    {
        h=0,v=0;
        cin>>a>>b>>c>>d;
        cin>>x>>y>>x1>>y1>>x2>>y2;
        h=x+b-a;
        v=y+d-c;
        if(x1==x2 && y1==y2)
        {
            if(a==0 && b==0 && c==0 && d==0)
                cout<<"Yes"<<endl;
            else
                cout<<"No"<<endl;
        }
        else if(x1==x2)
        {
            if(v>=y1 && v<=y2 && a==0 && b==0)
                cout<<"Yes"<<endl;
            else
               cout<<"No"<<endl;
        }
        else if(y1==y2)
        {
            if(h>=x1 && h<=x2 && c==0 && d==0)
                cout<<"Yes"<<endl;
            else
               cout<<"No"<<endl;
        }
        else if(h>=x1 && h<=x2 && v>=y1 && v<=y2)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long t,a,b,c,d,x,y,x1,y1,x2,y2,h,v;
    cin>>t;
    while(t--)
    {
        h=0,v=0;
        cin>>a>>b>>c>>d;
        cin>>x>>y>>x1>>y1>>x2>>y2;
        h=x+b-a;
        v=y+d-c;
        if(x1==x2 && y1==y2)
        {
            if(a==0 || b==0 || c==0 || d==0)
                cout<<"Yes"<<endl;
            else
                cout<<"No"<<endl;
        }
        else if(x1==x2)
        {
            if(v>=y1 && v<=y2)
                cout<<"Yes"<<endl;
            else
               cout<<"No"<<endl;
        }
        else if(y1==y2)
        {
            if(h>=x1 && h<=x2)
                cout<<"Yes"<<endl;
            else
               cout<<"No"<<endl;
        }
        else if(h>=x1 && h<=x2 && v>=y1 && v<=y2)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long t,a,b,c,d,x,y,x1,y1,x2,y2,h,v;
    cin>>t;
    while(t--)
    {
        h=0,v=0;
        cin>>a>>b>>c>>d;
        cin>>x>>y>>x1>>y1>>x2>>y2;
        h=x+b-a;
        v=y+d-c;
       if((x1==x2 && (x1==a || x1==b)) && (y1==y2 && (y1==c || y1==d)))
        {
            cout<<"No"<<endl;
        }
        else if(h>=x1 && h<=x2 && v>=y1 && v<=y2)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define mp make_pair
#define ok cout<<"ok\n";
#define pii pair<int,int>
#define piii pair<int,pii>

using namespace std;
typedef long long ll;
const int oo=(1<<30);
const int MAX=(1e5)+10;

int main (){

    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//    cout.setf(ios::fixed);cout.precision(0);
//    freopen("socdist2.in","r",stdin);
//    freopen("socdist2.out","w",stdout);

    int t;
    cin>>t;

    while(t--){
        int a,b,c,d,x,y,x1,x2,y1,y2;
        cin>>a>>b>>c>>d;
        cin>>x>>y>>x1>>y1>>x2>>y2;
        if(x1==x2 and (b!=0 or a!=0)){
            cout<<"No\n";
            continue;
        }
        if(y2==y1 and (c!=0 or d!=0)){
            cout<<"No";
            continue;
        }
        if(a>b){
            a-=b;
            b=0;
        }else{
            b-=a;
            a=0;
        }
        if(c>d){
            c-=d;
            d=0;
        }else{
            d-=c;
            c=0;
        }
        x+=a;
        x+=(b*-1);
        y+=c;
        y+=(c*-1);
        if(x>=x1 and x<=x2 and y<=y2 and y>=y1){
            cout<<"Yes\n";
        }else{
            cout<<"No\n";
        }
    }

    return 0;
}
/*

*/


#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define mp make_pair
#define ok cout<<"ok\n";
#define pii pair<int,int>
#define piii pair<int,pii>

using namespace std;
typedef long long ll;
const int oo=(1<<30);
const int MAX=(1e5)+10;

int main (){

    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//    cout.setf(ios::fixed);cout.precision(0);
//    freopen("socdist2.in","r",stdin);
//    freopen("socdist2.out","w",stdout);

    int t;
    cin>>t;

    while(t--){
        int a,b,c,d,x,y,x1,x2,y1,y2;
        cin>>a>>b>>c>>d;
        cin>>x>>y>>x1>>y1>>x2>>y2;
        if(x1==x2 and (b!=0 or a!=0)){
            cout<<"No\n";
            continue;
        }
        if(y2==y1 and (c!=0 or d!=0)){
            cout<<"No";
            continue;
        }
        if(a>b){
            a-=b;
            b=0;
        }else{
            b-=a;
            a=0;
        }
        if(c>d){
            c-=d;
            d=0;
        }else{
            d-=c;
            c=0;
        }
        x+=b;
        x+=(a*-1);
        y+=d;
        y+=(c*-1);
        if(x>=x1 and x<=x2 and y<=y2 and y>=y1){
            cout<<"Yes\n";
        }else{
            cout<<"No\n";
        }
    }

    return 0;
}
/*

*/


#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define mp make_pair
#define ok cout<<"ok\n";
#define pii pair<int,int>
#define piii pair<int,pii>

using namespace std;
typedef long long ll;
const int oo=(1<<30);
const int MAX=(1e5)+10;

int main (){

    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//    cout.setf(ios::fixed);cout.precision(0);
//    freopen("socdist2.in","r",stdin);
//    freopen("socdist2.out","w",stdout);

    int t;
    cin>>t;

    while(t--){
        int a,b,c,d,x,y,x1,x2,y1,y2;
        cin>>a>>b>>c>>d;
        cin>>x>>y>>x1>>y1>>x2>>y2;
        if(x1==x2 and (b!=0 or a!=0)){
            cout<<"No\n";
            continue;
        }
        if(y2==y1 and (c!=0 or d!=0)){
            cout<<"No\n";
            continue;
        }
        if(a>b){
            a-=b;
            b=0;
        }else{
            b-=a;
            a=0;
        }
        if(c>d){
            c-=d;
            d=0;
        }else{
            d-=c;
            c=0;
        }
        x+=b;
        x+=(a*-1);
        y+=d;
        y+=(c*-1);
        if(x>=x1 and x<=x2 and y<=y2 and y>=y1){
            cout<<"Yes\n";
        }else{
            cout<<"No\n";
        }
    }

    return 0;
}
/*

*/


#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define mp make_pair
#define ok cout<<"ok\n";
#define pii pair<int,int>
#define piii pair<int,pii>

using namespace std;
typedef long long ll;
const int oo=(1<<30);
const int MAX=(1e5)+10;

int main (){

    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//    cout.setf(ios::fixed);cout.precision(0);
//    freopen("socdist2.in","r",stdin);
//    freopen("socdist2.out","w",stdout);

    int t;
    cin>>t;

    while(t--){
        int a,b,c,d,x,y,x1,x2,y1,y2;
        cin>>a>>b>>c>>d;
        cin>>x>>y>>x1>>x2>>y1>>y2;
        if(x1==x2 and (b!=0 or a!=0)){
            cout<<"No\n";
            continue;
        }
        if(y2==y1 and (c!=0 or d!=0)){
            cout<<"No";
            continue;
        }
        if(a>b){
            a-=b;
            b=0;
        }else{
            b-=a;
            a=0;
        }
        if(c>d{
            c-=d;
            d=0;
        }else{
            d-=c;
            c=0;
        }
        x+=a;
        x+=(b*-1);
        y+=c;
        y+=(c*-1);
        if(x>=x1 and x<=x2 and y<=y2 and y>=y1){
            cout<<"Yes\n";
        }else{
            cout<<"No\n";
        }
    }

    return 0;
}
/*

*/


#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define mp make_pair
#define ok cout<<"ok\n";
#define pii pair<int,int>
#define piii pair<int,pii>

using namespace std;
typedef long long ll;
const int oo=(1<<30);
const int MAX=(1e5)+10;

int main (){

    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//    cout.setf(ios::fixed);cout.precision(0);
//    freopen("socdist2.in","r",stdin);
//    freopen("socdist2.out","w",stdout);

    int t;
    cin>>t;

    while(t--){
        int a,b,c,d,x,y,x1,x2,y1,y2;
        cin>>a>>b>>c>>d;
        cin>>x>>y>>x1>>x2>>y1>>y2;
        if(x1==x2 and (b!=0 or a!=0)){
            cout<<"No\n";
            continue;
        }
        if(y2==y1 and (c!=0 or d!=0)){
            cout<<"No";
            continue;
        }
        if(a>b){
            a-=b;
            b=0;
        }else{
            b-=a;
            a=0;
        }
        if(c>d){
            c-=d;
            d=0;
        }else{
            d-=c;
            c=0;
        }
        x+=a;
        x+=(b*-1);
        y+=c;
        y+=(c*-1);
        if(x>=x1 and x<=x2 and y<=y2 and y>=y1){
            cout<<"Yes\n";
        }else{
            cout<<"No\n";
        }
    }

    return 0;
}
/*

*/


#include<iostream>
#include<cstdio>
using namespace std;
int T,a,b,c,d;
int x,y,x1,x2,y1,y2;
int main()
{	scanf("%d",&T);
	while(T--)
	{	scanf("%d%d%d%d",&a,&b,&c,&d);
		scanf("%d%d%d%d%d%d",&x,&y,&x1,&y1,&x2,&y2);
	    if(a>b&&a-b>x-x1)printf("No\n");
	    else if(b>a&&b-a>x2-x)printf("No\n");
	    else if(c>d&&c-d>y-y1)printf("No\n");
	    else if(c<d&&d-c>y2-y)printf("No\n");
		else if(x2-x==0&&b&&(!a||x-x1==0))printf("No\n");
		else if(x-x1==0&&a&&(!b||x2-x==0))printf("No\n");
		else if(y2-y==0&&d&&(!c||y-y1==0))printf("No\n");
		else if(y-y1==0&&c&&(!d||y2-y==0))printf("No\n");
		else printf("Yes\n");
	}
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int T,a,b,c,d;
int x,y,x1,y1,x2,y2;
bool w(int xx,int yy)
{	if(xx>=x1&&xx<=x2&&yy>=y1&&yy<=y2)return 1;
	return 0;
}
int main()
{	scanf("%d",&T);
	while(T--)
	{	scanf("%d%d%d%d",&a,&b,&c,&d);
		scanf("%d%d%d%d%d%d",&x,&y,&x1,&y1,&x2,&y2);
		if(!w(x-a,y)&&!w(x+b,y)){printf("NO\n");continue;}
		if(!w(x,y-c)&&!w(x,y+d)){printf("NO\n");continue;}
		if(!w(x-a+b,y)||!w(x,y+d-c)){printf("NO\n");continue;}
		printf("YES\n");
	}
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int T,a,b,c,d;
int x,y,x1,y1,x2,y2;
bool w(int xx,int yy)
{	if(xx>=x1&&xx<=x2&&yy>=y1&&yy<=y2)return 1;
	return 0;
}
int main()
{	scanf("%d",&T);
	while(T--)
	{	scanf("%d%d%d%d",&a,&b,&c,&d);
		scanf("%d%d%d%d%d%d",&x,&y,&x1,&y1,&x2,&y2);
		if(!w(x-a,y)&&!w(x+b,y)){printf("No\n");continue;}
		if(!w(x,y-c)&&!w(x,y+d)){printf("No\n");continue;}
		if(!w(x-a+b,y)||!w(x,y-c+d)){printf("No\n");continue;}
		printf("Yes\n");
	}
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int T,a,b,c,d;
int x,y,x1,y1,x2,y2;
bool w(int xx,int yy)
{	if(xx>=x1&&xx<=x2&&yy>=y1&&yy<=y2)return 1;
	return 0;
}
int main()
{	scanf("%d",&T);
	while(T--)
	{	scanf("%d%d%d%d",&a,&b,&c,&d);
		scanf("%d%d%d%d%d%d",&x,&y,&x1,&y1,&x2,&y2);
		if(!w(x-a,y)&&!w(x+b,y)){printf("No\n");continue;}
		if(!w(x,y-c)&&!w(x,y+d)){printf("No\n");continue;}
		if(!w(x-a+b,y-c+d)||!w(x,y)){printf("No\n");continue;}
		printf("Yes\n");
	}
	return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
long long x1,x2,y4,y2,x,y;
long long  a,b,c,d;
int main()
{   long long  t;
    scanf("%lld",&t);
    for(int i=1;i<=t;i++)
    {
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    scanf("%lld%lld%lld%lld%lld%lld",&x,&y,&x1,&y4,&x2,&y2);

    x+=b-a;
    y+=d-c;
    int p=0;
    if(x1<=x&&x2>=x&&y4<=y&&y2>=y)
    p=1;
    if(x1==x2&&y2==y4)
    {
        p=0;
    }
    if(p)
    printf("Yes\n");
    else
    {
        printf("No\n");
    }
    }
    return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
int x1,x2,y4,y2,x,y;
int a,b,c,d;
int main()
{   int t;
    scanf("%d",&t);
    for(int i=1;i<=t;i++)
    {
    scanf("%d%d%d%d",&a,&b,&c,&d);
    scanf("%d%d%d%d%d%d",&x,&y,&x1,&y4,&x2,&y2);

    x+=b-a;
    y+=d-c;
    int p=0;
    if(x1<=x&&x2>=x&&y4<=y&&y2>=y)
    p=1;
    if(x1==x2&&y2==y4)
    {
        p=0;
    }
    if(p)
    printf("Yes\n");
    else
    {
        printf("No\n");
    }
    }
    return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
long long x1,x2,y4,y2,x,y;
long long  a,b,c,d;
int main()
{   long long  t;
    scanf("%lld",&t);
    for(int i=1;i<=t;i++)
    {
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    scanf("%lld%lld%lld%lld%lld%lld",&x,&y,&x1,&y4,&x2,&y2);
    x+=b-a;
    y+=d-c;
    int p=0;
    if(x1<=x&&x2>=x&&y4<=y&&y2>=y)
    p=1;
    if(x1==x2||y2==y4)
    {
        p=0;
    }
    if(p)
    printf("Yes\n");
    else
    {
        printf("No\n");
    }
    }
    return 0;
}