#include<iostream>
#include<stack>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<string>
#include<cstring>
#include<map>
#include<numeric>
#include<sstream>
#include<cmath>
using namespace std;

#define debug(x...) fprintf(stderr,x)
#define pb push_back
#define mp make_pair
#define f(i,x,y) for(int i=x; i<y; i++)
#define FORS(it,A) for(set<int>::iterator it = A.begin(); it!= A.end(); it++)
#define quad(x) ((x)*(x))
#define clr(x,y) memset(x,y,sizeof x)
#define all(x) ((x).begin(), (x).end())
#define fst first
#define snd second
#define sz(X) (int)X.size()
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

int pd[1<<20];
const ll mod = 1000000007ll;
ll pot2[1<<20];
int main() {
	int n; cin >> n;
	f(i, 0, (1<<20)) {
		pd[i] = 0;
		pot2[i] = (!i) ? 1LL : (pot2[i-1]*2LL) % mod;
	}
	f(i, 0, n) { int a; scanf("%d", &a); pd[a]++; }

	f(i, 0, 20) f(j, 0, (1<<20))
		if ((j & (1<<i)) == 0) pd[j] += pd[j | (1<<i)];
	ll resp = 0;
	f(i, 0, (1<<20)) {
		if (__builtin_popcount(i) & 1) resp = (resp + mod - pot2[pd[i]]) % mod;
		else resp = (resp + pot2[pd[i]]) % mod;
	}
	cout << resp << endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define FORE(ii,aa,bb) for(int ii=aa;ii<bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)
#define type(x) __typeof(x.begin())

#define bit(x,y) ((x>>y)&1)
#define y1 fkfrgff
#define int long long
#define pii pair<int,int>
#define mod 1000000007
#define N (int)(3e6+10)
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define endll puts("")
#define endl '\n'
#define inf mod
#define ort ((sol+sag)/2)
int n,dp[N],a[N],pw[N],t,ans;
main(){
	cin >> n;
	pw[0] = 1;
	FOR(i,1,n)
		pw[i] = (pw[i-1]*2)%mod;
	FOR(i,1,n){
		scanf("%lld",&a[i]);
		dp[a[i]]++;
	}
	FOR(j,0,20)
		ROF(i,2000000,0)
			if(bit(i,j) == 1)
				dp[i - (1 << j)] += dp[i];

	FOR(i,0,2000000){
		t = __builtin_popcount(i);
		if(t % 2) ans = (ans -	pw[dp[i]]) % mod;
		else ans = (ans + pw[dp[i]]) % mod;
	}
	cout << ((ans+1) % mod + mod) % mod << endl;
}


#include<bits/stdc++.h>

using namespace std;
#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define FORE(ii,aa,bb) for(int ii=aa;ii<bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)
#define type(x) __typeof(x.begin())

#define bit(x,y) ((x>>y)&1)
#define y1 fkfrgff
#define int long long
#define pii pair<int,int>
#define mod 1000000007
#define N (int)(3e6+10)
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define endll puts("")
#define endl '\n'
#define inf mod
#define ort ((sol+sag)/2)
int n,dp[N],a[N],pw[N],t,ans;
main(){
	cin >> n;
	pw[0] = 1;
	FOR(i,1,20)
		pw[i] = pw[i-1]*2;
	FOR(i,1,n){
		scanf("%lld",&a[i]);
		dp[a[i]]++;
	}
	FOR(j,0,20)
		ROF(i,2000000,0)
			if(bit(i,j) == 1)
				dp[i - (1 << j)] += dp[i];

	FOR(i,0,2000000){
		t = __builtin_popcount(i);
		if(t % 2) ans = (ans -	pw[dp[i]]) % mod;
		else ans = (ans + pw[dp[i]]) % mod;
	}
	cout << ans+1 << endl;
}


#include<bits/stdc++.h>

using namespace std;
#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define FORE(ii,aa,bb) for(int ii=aa;ii<bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)
#define type(x) __typeof(x.begin())

#define bit(x,y) ((x>>y)&1)
#define y1 fkfrgff
#define int long long
#define pii pair<int,int>
#define mod 1000000007
#define N (int)(1e6+10)
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define endll puts("")
#define endl '\n'
#define inf mod
#define ort ((sol+sag)/2)
int n,dp[N],a[N],pw[N],t,ans;
main(){
	cin >> n;
	pw[0] = 1;
	FOR(i,1,20)
		pw[i] = pw[i-1]*2;
	FOR(i,1,n){
		scanf("%lld",&a[i]);
		dp[a[i]]++;
	}
	FOR(j,0,19)
		ROF(i,1000000,0)
			if(bit(i,j) == 1)
				dp[i - (1 << j)] += dp[i];

	FOR(i,0,1000000){
		t = __builtin_popcount(i);
		if(t % 2) ans = (ans -	pw[dp[i]]) % mod;
		else ans = (ans + pw[dp[i]]) % mod;
	}
	cout << ans+1 << endl;
}


#include<bits/stdc++.h>

using namespace std;
#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define FORE(ii,aa,bb) for(int ii=aa;ii<bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)
#define type(x) __typeof(x.begin())

#define bit(x,y) ((x>>y)&1)
#define y1 fkfrgff
#define int long long
#define pii pair<int,int>
#define mod 1000000007
#define N (int)(3e6+10)
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define endll puts("")
#define endl '\n'
#define inf mod
#define ort ((sol+sag)/2)
int n,dp[N],a[N],pw[N],t,ans;
main(){
	cin >> n;
	pw[0] = 1;
	FOR(i,1,n)
		pw[i] = (pw[i-1]*2)%mod;
	FOR(i,1,n){
		scanf("%lld",&a[i]);
		dp[a[i]]++;
	}
	FOR(j,0,20)
		ROF(i,2000000,0)
			if(bit(i,j) == 1)
				dp[i - (1 << j)] += dp[i];

	FOR(i,0,2000000){
		t = __builtin_popcount(i);
		if(t % 2) ans = (ans -	pw[dp[i]]) % mod;
		else ans = (ans + pw[dp[i]]) % mod;
	}
	cout << ans+1 << endl;
}


#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#define mk make_pair
using namespace std;
int i,j,k,l,n,m,s,an,tot,K,M;
const int N=1110000;
const int pp=1000000007;
int a[N],f[N],num[N],f2[N];
int quick(int x,int y)
{
	int xx=1;
	while (y)
	{
		if (y&1) xx=(long long)xx*x%pp;
		x=(long long)x*x%pp;
		y/=2;
	}
	return xx;
}
int main()
{
	scanf("%d",&n);
	M=1<<20;
	M--;
	//M=1000001;
	for (int i=1;i<M;i++)
	{
		int x=i;
		while (x)
		{
			if (x&1) num[i]++;
			x/=2;
		}
	}
	for (int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		if (num[x]<=10)
		a[x]++;
		else
		{
			x=M^x;
			f2[x]++;
		}
		//for (int i=x;i;i=(i-1)&x)
		//a[i]++;
	}
	for (int now=1;now<1<<11;now++)
	if (a[now])
	for (int i=now;i;i=(i-1)&now)
	f[i]+=a[now];
	an=quick(2,n)-1;
	for (int now=1;now<M;now++)
	{
		//int s=0;
		//for (int i=now;i;i=(i-1)&now)
		if (num[now]<=10)
		{
		int s=f[now];
		if (!(num[now]&1)) an=(an+quick(2,s)-1)%pp;
		else an=(an-quick(2,s)+1)%pp;
		}
		else
		{
			int x=M^now;
			int s=0;
			for (int i=x;i;i=(i-1)&x)
			s+=f2[i];
			if (!(num[x]&1)) an=(an+quick(2,s)-1)%pp;
			else an=(an-quick(2,s)+1)%pp;
		}
	}
	printf("%d\n",(an+pp)%pp);

	return 0;
}


#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#define mk make_pair
using namespace std;
int i,j,k,l,n,m,s,an,tot,K,M;
const int N=1110000;
const int pp=1000000007;
int a[N],f[N];
int quick(int x,int y)
{
	int xx=1;
	while (y)
	{
		if (y&1) xx=(long long)xx*x%pp;
		x=(long long)x*x%pp;
		y/=2;
	}
	return xx;
}
int main()
{
	scanf("%d",&n);
	M=1<<20;
	M--;
	for (int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		a[x]++;
		//for (int i=x;i;i=(i-1)&x)
		//a[i]++;
	}
	for (int now=1;now<M;now++)
	if (a[now])
	for (int i=now;i;i=(i-1)&now)
	f[i]+=a[now];

	an=quick(2,n)-1;
	for (int now=1;now<M;now++)
	{
		//int s=0;
		//for (int i=now;i;i=(i-1)&now)
		int s=f[now];
		int x=now;
		int ss=0;
		while (x)
		{
			if (x&1) ss++;
			x/=2;
		}
		if (!(ss&1)) an=(an+quick(2,s)-1)%pp;
		else an=(an-quick(2,s)+1)%pp;
	}
	printf("%d\n",(an+pp)%pp);
	//for(;;);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#define mk make_pair
using namespace std;
int i,j,k,l,n,m,s,an,tot,K,M;
const int N=1110000;
const int pp=1000000007;
int a[N],f[N],num[N],f2[N];
int quick(int x,int y)
{
	int xx=1;
	while (y)
	{
		if (y&1) xx=(long long)xx*x%pp;
		x=(long long)x*x%pp;
		y/=2;
	}
	return xx;
}
int main()
{
	scanf("%d",&n);
	M=1<<20;
	M--;
	//M=1000001;
	for (int i=1;i<M;i++)
	{
		int x=i;
		while (x)
		{
			if (x&1) num[i]++;
			x/=2;
		}
	}
	for (int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		f[x]++;
	}
	for (int k=0;k<20;k++)
	for (int i=0;i<=M;i++)
	if (!(i&(1<<k))) f[i]+=f[i|(1<<k)];
	an=quick(2,n)-1;
	for (int now=1;now<M;now++)
	{
		//int s=0;
		//for (int i=now;i;i=(i-1)&now)
		int s=0;
		s+=f[now];
		if (!(num[now]&1)) an=(an+quick(2,s)-1)%pp;
		else an=(an-quick(2,s)+1)%pp;
	}
	printf("%d\n",(an+pp)%pp);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#define mk make_pair
using namespace std;
int i,j,k,l,n,m,s,an,tot,K,M;
const int N=1110000;
const int pp=1000000007;
int a[N];
int quick(int x,int y)
{
	int xx=1;
	while (y)
	{
		if (y&1) xx=(long long)xx*x%pp;
		x=(long long)x*x%pp;
		y/=2;
	}
	return xx;
}
int main()
{
	scanf("%d",&n);
	M=1<<20;
	M--;
	for (int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		for (int i=x;i;i=(i-1)&x)
		a[i]++;
	}
	an=quick(2,n)-1;
	for (int now=1;now<M;now++)
	{
		//int s=0;
		//for (int i=now;i;i=(i-1)&now)
		int s=a[now];
		int x=now;
		int ss=0;
		while (x)
		{
			if (x&1) ss++;
			x/=2;
		}
		if (!(ss&1)) an=(an+quick(2,s)-1)%pp;
		else an=(an-quick(2,s)+1)%pp;
	}
	printf("%d\n",(an+pp)%pp);
	//for(;;);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#define mk make_pair
using namespace std;
int i,j,k,l,n,m,s,an,tot,K,M;
const int N=1110000;
const int pp=1000000007;
int a[N];
int quick(int x,int y)
{
	int xx=1;
	while (y)
	{
		if (y&1) xx=(long long)xx*x%pp;
		x=(long long)x*x%pp;
		y/=2;
	}
	return xx;
}
int main()
{
	scanf("%d",&n);
	M=1<<20;
	M--;
	for (int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		a[M^x]++;
	}
	an=quick(2,n)-1;
	for (int now=1;now<M;now++)
	{
		int s=0;
		for (int i=now;i;i=(i-1)&now)
		s+=a[i];
		int x=now;
		int ss=0;
		while (x)
		{
			if (x&1) ss++;
			x/=2;
		}
		if (!(ss&1)) an=(an+quick(2,s)-1)%pp;
		else an=(an-quick(2,s)+1)%pp;
	}
	printf("%d\n",(an+pp)%pp);
	//for(;;);
	return 0;
}


#include <cstdio>
typedef long long LL;
const LL mod=1000000007LL;
int dp[1050000][21];
LL ans=0;
inline int cnt(int x)
{
    int ans=0;
    while(x)
        ans+=x&1,x>>=1;
    return ans;
}
LL pow_mod(LL a,int n)
{
    LL ans=1;
    while(n)
    {
        if(n&1)
            ans=ans*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans;
}
void solve()
{
    for(int i=0;i<=1048575;++i)
    {
        if(cnt(i)&1)
            ans-=pow_mod(2,dp[i][20]);
        else ans+=pow_mod(2,dp[i][20]);
        ans%=mod;
    }
    if(ans<0)
        ans+=mod;
}
int main()
{
    int n,a;
    scanf("%d",&n);
    while(n--)
        scanf("%d",&a),++dp[a][0];
    int i,j;
    for(j=1;j<=20;++j)
        for(i=0;i<=1000000;++i)
        {
            dp[i][j]=dp[i][j-1];
            if(!(i&(1<<(j-1))))
                dp[i][j]+=dp[i|(1<<(j-1))][j-1];
        }
    ans=0;
    solve();
    printf("%I64d\n",ans);
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
const int N = 1e6+10;
const int MOD = 1E9+7;
const int LOGN = 21;
int n,m,data[N];
int two[50];
int f[LOGN][N];
int scan(){int i=0;scanf("%d",&i);return i;}
void update(int &a,int b){
	a+=b;
	if(a >= MOD)a-=MOD;
	if(a < 0)  a+=MOD;
}
int pow(int x,int k){
	int re=1;
	for(;k;k/=2,x=(x*x)%MOD)
	if(k&1)re = (re*x)%MOD;
	return re;
}
int main(){
	int i,j;
	for(two[0] = 1,i = 1;i<=30;i++)two[i] = two[i-1]*2;
	int mn=0,mlogn,ans=0;
	n = scan();
	for(i=1;i<=n;i++)mn = max(mn,(data[i] = scan()));
	mlogn = log2(mn);
	for(i=1;i<=n;i++)f[0][data[i]]++;

	//f[i][j] ±íÊ¾iÎ»ÒÔºó±ØÐëÍêÈ«ÏàÍ¬£¬Ç°iÎ»Ö»Òªand½á¹û²»±ä¾ÍÐÐ
	//f[?][j] & x = x
	for(i=0;i<=mlogn;i++)
	for(j=0;j<=mn;j++){
		if(j & two[i])
			update(f[i+1][j],f[i][j]),
			update(f[i+1][j^two[i]],f[i][j]);
		else
			update(f[i+1][j],f[i][j]);
	}

	for(i=0;i<=mn;i++){
		int tmp = pow(2,f[mlogn+1][i])-1,cot=0,ii=i;
		for(;ii;ii/=2)if(ii&1)cot++;
		if(cot&1)update(ans,-tmp);
		else update(ans,tmp);
	}
	printf("%d\n",ans);
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
const int N = 1e6+10;
const int MOD = 1E9+7;
const int LOGN = 21;
int n,m,data[N];
int two[50];
int f[LOGN][N];
int scan(){int i=0;scanf("%d",&i);return i;}
void update(int &a,int b){
	a+=b;
	if(a > MOD)a-=MOD;
	if(a < 0)  a+=MOD;
}
int pow(int x,int k){
	int re=1;
	for(;k;k/=2,x=(x*x)%MOD)
	if(k&1)re = (re*x)%MOD;
	return re;
}
int main(){
	int i,j;
	for(two[0] = 1,i = 1;i<=30;i++)two[i] = two[i-1]*2;
	int mn=0,mlogn,ans=0;
	n = scan();
	for(i=1;i<=n;i++)mn = max(mn,(data[i] = scan()));
	mlogn = log2(mn);
	for(i=1;i<=n;i++)f[0][data[i]]++;

	//f[i][j] ±íÊ¾iÎ»ÒÔºó±ØÐëÍêÈ«ÏàÍ¬£¬Ç°iÎ»Ö»Òªand½á¹û²»±ä¾ÍÐÐ
	//f[?][j] & x = x
	for(i=0;i<=mlogn;i++)
	for(j=0;j<=mn;j++){
		if(j & two[i])
			update(f[i+1][j],f[i][j]),
			update(f[i+1][j^two[i]],f[i][j]);
		else
			update(f[i+1][j],f[i][j]);
	}

	for(i=0;i<=mn;i++){
		int tmp = pow(2,f[mlogn+1][i])-1,cot=0,ii=i;
		for(;ii;ii/=2)if(ii&1)cot++;
		if(cot&1)update(ans,-tmp);
		else update(ans,tmp);
	}
	printf("%d\n",ans);
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
const int N = 1e6+10;
const int MOD = 1E9+7;
const int LOGN = 21;
int n,m,data[N];
int two[50];
int f[LOGN][N];
int scan(){int i=0;scanf("%d",&i);return i;}
void update(int &a,int b){
	a+=b;
	if(a >= MOD)a-=MOD;
	if(a < 0)  a+=MOD;
}
int pow(int x,int k){
	int re=1;
	for(;k;k/=2,x=((long long)x*x)%MOD)
	if(k&1)re = ((long long)re*x)%MOD;
	return re;
}
int main(){
	//freopen("in.txt", "r", stdin);
	int i,j;
	for(two[0] = 1,i = 1;i<=30;i++)two[i] = two[i-1]*2;
	int mn=0,mlogn,ans=0;
	n = scan();
	for(i=1;i<=n;i++)mn = max(mn,(data[i] = scan()));
	mlogn = log2(mn);
	for(i=1;i<=n;i++)f[0][data[i]]++;

	//f[i][j] ±íÊ¾iÎ»ÒÔºó±ØÐëÍêÈ«ÏàÍ¬£¬Ç°iÎ»Ö»Òªand½á¹û²»±ä¾ÍÐÐ
	//f[?][j] & x = x
	for(i=0;i<=mlogn;i++)
	for(j=0;j<=mn;j++){
		if(j & two[i])
			update(f[i+1][j],f[i][j]),
			update(f[i+1][j^two[i]],f[i][j]);
		else
			update(f[i+1][j],f[i][j]);
	}

	for(i=0;i<=mn;i++){
		int tmp = pow(2,f[mlogn+1][i])-1,cot=0,ii=i;
		for(;ii;ii/=2)if(ii&1)cot++;
		if(cot&1)update(ans,-tmp);
		else update(ans,tmp);
	}
	printf("%d\n",ans);
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
const int N = 1e6+10;
const int MOD = 1E9+7;
const int LOGN = 21;
int n,m,data[N];
int two[50];
int f[LOGN][N];
int scan(){int i=0;scanf("%d",&i);return i;}
void update(int &a,int b){
	a+=b;
	if(a >= MOD)a-=MOD;
	if(a < 0)  a+=MOD;
}
int pow(int x,int k){
	int re=1;
	for(;k;k/=2,x=((long long)x*x)%MOD)
	if(k&1)re = ((long long)re*x)%MOD;
	return re;
}
int main(){
	//freopen("in.txt", "r", stdin);
	int i,j;
	for(two[0] = 1,i = 1;i<=30;i++)two[i] = two[i-1]*2;
	int mn=0,mlogn,ans=0;
	n = scan();
	for(i=1;i<=n;i++)mn = max(mn,(data[i] = scan()));
	if(mn)mlogn = log2(mn);
	else mlogn=0;
	for(i=1;i<=n;i++)f[0][data[i]]++;

	//f[i][j] ±íÊ¾iÎ»ÒÔºó±ØÐëÍêÈ«ÏàÍ¬£¬Ç°iÎ»Ö»Òªand½á¹û²»±ä¾ÍÐÐ
	//f[?][j] & x = x
	for(i=0;i<=mlogn;i++)
	for(j=0;j<=mn;j++){
		if(j & two[i])
			update(f[i+1][j],f[i][j]),
			update(f[i+1][j^two[i]],f[i][j]);
		else
			update(f[i+1][j],f[i][j]);
	}

	for(i=0;i<=mn;i++){
		int tmp = pow(2,f[mlogn+1][i])-1,cot=0,ii=i;
		for(;ii;ii/=2)if(ii&1)cot++;
		if(cot&1)update(ans,-tmp);
		else update(ans,tmp);
	}
	printf("%d\n",ans);
	return 0;
}


/*
Author: 1412kid1412@UESTC
*/

#include <stdexcept>
#include <cstdarg>
#include <iostream>
#include <fstream>
#include <exception>
#include <memory>
#include <locale>
#include <sstream>
#include <set>
#include <list>
#include <bitset>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <string>
#include <utility>
#include <cctype>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <deque>
#include <cstdlib>
#include <stack>
#include <iterator>
#include <functional>
#include <complex>
#include <valarray>
using namespace std;

int cnt[1<<20|1];
int dp[20][1<<20|1];
const int N=1000000;
const int mod=1000000007;

#define p(x) (1LL<<(x))
int f[N|1];

int calbit(int x){
    int ret=0;
    while(x){
        ret++;
        x-=(x&-x);
    }
    return ret;
}

int main(){
    f[0]=1;
    for(int i=0;i<=N;i++){
        f[i+1]=(f[i]<<1);
        f[i+1]%=mod;
    }
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int x;
        scanf("%d",&x);
        cnt[x]++;
    }
    for(int i=0;i<=N;i++){
        if(i&1){
            dp[0][i]=cnt[i];
        }
        else{
            dp[0][i]=cnt[i]+cnt[i^1];
        }
    }
    for(int i=1;i<20;i++){
        for(int j=0;j<=N;j++){
            if(p(i)&j){
                dp[i][j]=dp[i-1][j];
            }
            else{
                dp[i][j]=(dp[i-1][j]+dp[i-1][j^p(i)])%mod;
            }
        }
    }
    int ret=0;
    for(int i=0;i<(1<<20);i++){
        if(calbit(i)&1){
            ret+=(mod-f[dp[19][i]]%mod);
            ret%=mod;
        }
        else{
            ret+=f[dp[19][i]];
            ret%=mod;
        }
        ret%=mod;
    }
    printf("%d\n",ret%mod);
    return 0;
}


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

const int N=1001000;
const int mod=1000000007;
int p[N],a[N];

void tf(int a[],int l,int r){
    if(l+1==r)return ;
    int len=(r-l)>>1,mid=l+len;
    tf(a,l,mid);
    tf(a,mid,r);
    for(int i=l;i<mid;i++){
        a[i]+=a[i+len];
        a[i]%=mod;
    }
}

void utf(int a[],int l,int r){
    if(l+1==r)return ;
    int len=(r-l)>>1,mid=l+len;
    for(int i=l;i<mid;i++){
        a[i]=a[i]+mod-a[i+len];
        a[i]%=mod;
    }
    utf(a,l,mid);
    utf(a,mid,r);
}
int main(){
    p[0]=1;
    for(int i=0;i<=1000000;i++){
        p[i+1]=(p[i]<<1)%mod;
    }
    int n;
    scanf("%d",&n);
    int len=1;
    for(;len<n;len<<=1);
    for(int i=0;i<n;i++){
        int x;
        scanf("%d",&x);
        a[x]++;
    }
    tf(a,0,len);
    for(int i=0;i<len;i++){
        a[i]=p[a[i]];
    }
    utf(a,0,len);
    printf("%d\n",a[0]);

    return 0;
}


/*
Author: 1412kid1412@UESTC
*/

#include <stdexcept>
#include <cstdarg>
#include <iostream>
#include <fstream>
#include <exception>
#include <memory>
#include <locale>
#include <sstream>
#include <set>
#include <list>
#include <bitset>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <string>
#include <utility>
#include <cctype>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <deque>
#include <cstdlib>
#include <stack>
#include <iterator>
#include <functional>
#include <complex>
#include <valarray>
using namespace std;

int cnt[1<<20|1];
int dp[20][1<<20|1];
const int N=1000000;
const int mod=1000000007;

#define p(x) (1LL<<(x))
int f[N|1];

int calbit(int x){
	int ret=0;
	while(x){
		ret++;
		x-=(x&-x);
	}
	return ret;
}

int main(){
	f[0]=1;
	for(int i=0;i<=N;i++){
		f[i+1]=(f[i]<<1);
		f[i+1]%=mod;
	}
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		cnt[x]++;
	}
	for(int i=0;i<=N;i++){
		if(i&1){
			dp[0][i]=cnt[i];
		}
		else{
			dp[0][i]=cnt[i]+cnt[i^1];
		}
	}
	for(int i=1;i<20;i++){
		for(int j=0;j<=N;j++){
			if(p(i)&j){
				dp[i][j]=dp[i-1][j];
			}
			else{
				dp[i][j]=(dp[i-1][j]+dp[i-1][j^p(i)])%mod;
			}
		}
	}
	int ret=0;
	for(int i=0;i<=N;i++){
		if(!dp[19][i]){
			continue;
		}
		if(calbit(i)&1){
			ret+=(mod-f[dp[19][i]]%mod);
			ret%=mod;
		}
		else{
			ret+=f[dp[19][i]];
			ret%=mod;
		}
		ret%=mod;
	}
	printf("%d\n",ret);
	return 0;
}


/*
Author: 1412kid1412@UESTC
*/

#include <stdexcept>
#include <cstdarg>
#include <iostream>
#include <fstream>
#include <exception>
#include <memory>
#include <locale>
#include <sstream>
#include <set>
#include <list>
#include <bitset>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <string>
#include <utility>
#include <cctype>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <deque>
#include <cstdlib>
#include <stack>
#include <iterator>
#include <functional>
#include <complex>
#include <valarray>
using namespace std;

int cnt[1<<20|1];
int dp[20][1<<20|1];
const int N=1000000;
const int mod=1000000007;

#define p(x) (1LL<<(x))
int f[N|1];

int calbit(int x){
	int ret=0;
	while(x){
		ret++;
		x-=(x&-x);
	}
	return ret;
}

int main(){
	f[0]=1;
	for(int i=0;i<=N;i++){
		f[i+1]=(f[i]<<1);
		f[i+1]%=mod;
	}
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		cnt[x]++;
	}
	for(int i=0;i<=N;i++){
		if(i&1){
			dp[0][i]=cnt[i];
		}
		else{
			dp[0][i]=cnt[i]+cnt[i^1];
		}
	}
	for(int i=1;i<20;i++){
		for(int j=0;j<=N;j++){
			if(p(i)&j){
				dp[i][j]=dp[i-1][j];
			}
			else{
				dp[i][j]=(dp[i-1][j]+dp[i-1][j^p(i)])%mod;
			}
		}
	}
	int ret=0;
	for(int i=0;i<=N;i++){
		if(calbit(i)&1){
			ret+=(mod-f[dp[19][i]]%mod);
			ret%=mod;
		}
		else{
			ret+=f[dp[19][i]];
			ret%=mod;
		}

		ret%=mod;
	}
	printf("%d\n",(ret+1)%mod);
	return 0;
}


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

const int N=1001000;
const int mod=1000000007;
int p[1<<21],a[1<<21];

void tf(int a[],int l,int r){
    if(l+1==r)return ;
    int len=(r-l)>>1,mid=l+len;
    tf(a,l,mid);
    tf(a,mid,r);
    for(int i=l;i<mid;i++){
        a[i]+=a[i+len];
        a[i]%=mod;
    }
}

void utf(int a[],int l,int r){
    if(l+1==r)return ;
    int len=(r-l)>>1,mid=l+len;
    for(int i=l;i<mid;i++){
        a[i]=a[i]+mod-a[i+len];
        a[i]%=mod;
    }
    utf(a,l,mid);
    utf(a,mid,r);
}
int main(){
    p[0]=1;
    for(int i=0;i<=1000000;i++){
        p[i+1]=(p[i]<<1)%mod;
    }
    int n;
    scanf("%d",&n);
    int len=1;
    for(;len<n;len<<=1);
    for(int i=0;i<n;i++){
        int x;
        scanf("%d",&x);
        a[x]++;
    }
    tf(a,0,len);
    for(int i=0;i<len;i++){
        a[i]=p[a[i]];
    }
    utf(a,0,len);
    printf("%d\n",a[0]);

    return 0;
}


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

const int N=1001000;
const int mod=1000000007;
int p[1<<21],a[1<<21];

void tf(int a[],int l,int r){
    if(l+1==r)return ;
    int len=(r-l)>>1,mid=l+len;
    tf(a,l,mid);
    tf(a,mid,r);
    for(int i=l;i<mid;i++){
        a[i]+=a[i+len];
        a[i]%=mod;
    }
}

void utf(int a[],int l,int r){
    if(l+1==r)return ;
    int len=(r-l)>>1,mid=l+len;
    for(int i=l;i<mid;i++){
        a[i]=a[i]+mod-a[i+len];
        a[i]%=mod;
    }
    utf(a,l,mid);
    utf(a,mid,r);
}
int main(){
    p[0]=1;
    for(int i=0;i<=1000000;i++){
        p[i+1]=(p[i]<<1)%mod;
    }
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int x;
        scanf("%d",&x);
        a[x]++;
    }
    tf(a,0,1<<20);
    for(int i=0;i<(1<<20);i++){
        a[i]=p[a[i]];
    }
    utf(a,0,1<<20);
    printf("%d\n",a[0]);

    return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<vector>
#include<cstdlib>
#include<utility>
#define fs first
#define sc second
#define mp make_pair
#define clr clear
#define pb push_back
#define Max(a,b) ((a)<(b)?(b):(a))
#define Min(a,b) ((a)<(b)?(a):(b))
#define lowbit(x) ((x)&(-(x)))
#define ab(x) ((x)>0?(x):(-(x)))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> PI;
void read(int &tmp)
{
    char ch=getchar();tmp=0;int sgn=1;
    while (ch!=EOF && (ch<'0' || ch>'9') && ch!='-') ch=getchar();
    if (ch=='-') sgn=-1,ch=getchar();
    while (ch!=EOF && ch>='0' && ch<='9') tmp=tmp*10+ch-48,ch=getchar();
    tmp*=sgn;
}
const int maxn=1010000;
int n;
int a[maxn];
const ll mod=1000000007ll;
ll ans,pw[maxn<<2];
int totmask;
int s[maxn<<2],ss[maxn<<2],cnt[maxn<<2];
int main()
{
    cnt[0]=0;
    read(n);totmask=0;
    for (int i=1;i<=n;i++) read(a[i]),totmask|=a[i];
    for (int i=1;i<=n;i++) s[a[i]]++;
    for (int i=0;i<=totmask;i++) ss[i]=s[totmask^i];
    for (int i=0;totmask>=(1<<i);i++)
    {
        for (int mask=0;mask<=totmask;mask++)
        {
            if ((mask&(1<<i))==0)
            {
                ss[mask|(1<<i)]+=ss[mask];
            }
        }
    }
    for (int i=0;i<=totmask;i++) s[i]=ss[totmask^i];
    pw[0]=1ll;
    for (int i=1;i<=Max(totmask,n);i++) pw[i]=(pw[i-1]<<1ll)%mod;
    cnt[0]=0;
    for (int i=1;i<=Max(n,totmask);i++) cnt[i]=cnt[i^lowbit(i)]+1;
    ans=pw[n]-1ll;
    for (int i=1;i<=totmask;i++)
    {
        if (s[i])
        {
            if (cnt[i]&1)
            {
                ans -= (pw[s[i]]-1ll);
                ans=(ans%mod+mod)%mod;
            }else {
                        ans+=(pw[s[i]]-1ll);
                        ans=(ans%mod+mod)%mod;
                   }
        }
    }
    printf("%d\n",(int)(ans%mod));
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<vector>
#include<cstdlib>
#include<utility>
#define fs first
#define sc second
#define mp make_pair
#define clr clear
#define pb push_back
#define Max(a,b) ((a)<(b)?(b):(a))
#define Min(a,b) ((a)<(b)?(a):(b))
#define lowbit(x) ((x)&(-(x)))
#define ab(x) ((x)>0?(x):(-(x)))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> PI;
void read(int &tmp)
{
    char ch=getchar();tmp=0;int sgn=1;
    while (ch!=EOF && (ch<'0' || ch>'9') && ch!='-') ch=getchar();
    if (ch=='-') sgn=-1,ch=getchar();
    while (ch!=EOF && ch>='0' && ch<='9') tmp=tmp*10+ch-48,ch=getchar();
    tmp*=sgn;
}
const int maxn=1010000;
int n;
int a[maxn];
const ll mod=1000000007ll;
ll ans,pw[maxn<<2];
int totmask;
int s[maxn<<2],ss[maxn<<2],cnt[maxn<<2];
int main()
{

    cnt[0]=0;
    read(n);totmask=0;
    for (int i=1;i<=n;i++) read(a[i]),totmask|=a[i];
    for (int i=1;i<=n;i++) s[a[i]]++;
    for (int i=0;i<=totmask;i++)
            if ((totmask&i)==i)ss[i]=s[totmask^i];
    for (int i=0;totmask>=(1<<i);i++)
    {
        if (totmask&(1<<i))
        for (int mask=0;mask<=totmask;mask++)
        {
            if ((mask&(1<<i))==0)
            {
                ss[mask|(1<<i)]+=ss[mask];
            }
        }
    }
    for (int i=0;i<=totmask;i++)
        if ((totmask&i)==i)s[i]=ss[totmask^i];
    pw[0]=1ll;
    for (int i=1;i<=Max(totmask,n);i++) pw[i]=(pw[i-1]<<1ll)%mod;
    cnt[0]=0;
    for (int i=1;i<=Max(n,totmask);i++) cnt[i]=cnt[i^lowbit(i)]+1;
    ans=pw[n]-1ll;
    for (int i=1;i<=totmask;i++)
    {
        if (s[i])
        {
            if (cnt[i]&1)
            {
                ans -= (pw[s[i]]-1ll);
                ans=(ans%mod+mod)%mod;
            }else {
                        ans+=(pw[s[i]]-1ll);
                        ans=(ans%mod+mod)%mod;
                   }
        }
    }
    printf("%d\n",(int)(ans%mod));
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<vector>
#include<cstdlib>
#include<utility>
#define fs first
#define sc second
#define mp make_pair
#define clr clear
#define pb push_back
#define Max(a,b) ((a)<(b)?(b):(a))
#define Min(a,b) ((a)<(b)?(a):(b))
#define lowbit(x) ((x)&(-(x)))
#define ab(x) ((x)>0?(x):(-(x)))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> PI;
void read(int &tmp)
{
    char ch=getchar();tmp=0;int sgn=1;
    while (ch!=EOF && (ch<'0' || ch>'9') && ch!='-') ch=getchar();
    if (ch=='-') sgn=-1,ch=getchar();
    while (ch!=EOF && ch>='0' && ch<='9') tmp=tmp*10+ch-48,ch=getchar();
    tmp*=sgn;
}
const int maxn=1010000;
int n;
int a[maxn];
const ll mod=1000000007ll;
ll ans,pw[maxn<<2];
int totmask;
int s[maxn<<2],ss[maxn<<2],cnt[maxn<<2];
int main()
{
    cnt[0]=0;
    read(n);totmask=0;
    for (int i=1;i<=n;i++) read(a[i]),totmask|=a[i];
    for (int i=1;i<=n;i++) s[a[i]]++;
    for (int i=0;i<=totmask;i++) ss[i]=s[totmask^i];
    for (int i=0;totmask>=(1<<i);i++)
    {
        for (int mask=0;mask<=totmask;mask++)
        {
            if ((mask&(1<<i))==0)
            {
                ss[mask|(1<<i)]+=ss[mask];
            }
        }
    }
    for (int i=0;i<=totmask;i++) s[i]=ss[totmask^i];
    pw[0]=1ll;
    for (int i=1;i<=totmask;i++) pw[i]=(pw[i-1]<<1ll)%mod;
    cnt[0]=0;
    for (int i=1;i<=totmask;i++) cnt[i]=cnt[i^lowbit(i)]+1;
    ans=pw[n]-1ll;
    for (int i=1;i<=totmask;i++)
    {
        if (s[i])
        {
            if (cnt[i]&1)
            {
                ans -= (pw[s[i]]-1ll);
                ans=(ans%mod+mod)%mod;
            }else {
                        ans+=(pw[s[i]]-1ll);
                        ans=(ans%mod+mod)%mod;
                   }
        }
    }
    printf("%d\n",(int)(ans%mod));
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<algorithm>
#include<vector>
using namespace std;
#define N 2000000
int n,a[N],sum[N];
const int MOD=7+(int)1e9;
typedef long long LL;
LL ans;
LL f[N];
void print(int x){
	if(x==0)return;
	putchar((x&1)+'0');
	print(x>>1);
}
void solve(int l,int r){
	if(l==r){f[l]=sum[l];return;}
	int mid=(l+r)/2;
	solve(l,mid);
	solve(mid+1,r);
	for(int i=l;i<=mid;i++)f[i]+=f[i-l+1+mid],f[i]%=MOD;
}
int bitc(int x){
	return x==0?0:bitc(x>>1)^(x&1);
}
LL modpow(LL x,LL y){
	LL ret=1;
	x%=MOD;
	for(;y;y>>=1,(x*=x)%=MOD)
		if(y&1)(ret*=x)%=MOD;
	return ret;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),sum[a[i]]++;
	int all=1;
	while(all<1000000)all*=2;
	solve(0,all-1);
	for(int i=0;i<all;i++){
		LL w=bitc(i)?MOD-1:1;
		ans+=w*(modpow(2,f[i])-1)%MOD;
		ans%=MOD;
	}ans+=MOD;
	ans%=MOD;
	printf("%d\n",(int)ans);
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<algorithm>
#include<vector>
using namespace std;
#define N 2000000
int n,a[N],sum[N],f[N];
const int MOD=7+(int)1e9;
typedef long long LL;
LL ans;
void solve(int l,int r){
	if(l==r){f[l]=sum[l];return;}
	int mid=(l+r)/2;
	solve(l,mid);
	solve(mid+1,r);
	for(int i=l;i<=mid;i++)f[i]+=f[i-l+1+mid],f[i]%=MOD;
}
int bitc(int x){
	return x==0?0:bitc(x>>1)^(x&1);
}
LL modpow(LL x,LL y){
	LL ret=1;
	for(;y;y>>=1,(x*=x)%=MOD)
		if(y&1)(ret*=x)%=MOD;
	return ret;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),sum[a[i]]++;
	int all=1;
	while(all<100000)all*=2;
	solve(0,all-1);
	for(int i=0;i<all;i++){
		int w=bitc(i)?-1:1;
		ans+=(LL)w*modpow(2,f[i]);
		ans%=MOD;
	}ans+=MOD;
	ans%=MOD;
	printf("%d\n",(int)ans);
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<algorithm>
#include<vector>
using namespace std;
#define N 2000000
int n,a[N],sum[N];
const int MOD=7+(int)1e9;
typedef long long LL;
LL ans;
LL f[N];
void solve(int l,int r){
	if(l==r){f[l]=sum[l];return;}
	int mid=(l+r)/2;
	solve(l,mid);
	solve(mid+1,r);
	for(int i=l;i<=mid;i++)f[i]+=f[i-l+1+mid],f[i]%=MOD;
}
int bitc(int x){
	return x==0?0:bitc(x>>1)^(x&1);
}
LL modpow(LL x,LL y){
	LL ret=1;
	for(;y;y>>=1,(x*=x)%=MOD)
		if(y&1)(ret*=x)%=MOD;
	return ret;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),sum[a[i]]++;
	int all=1;
	while(all<100000)all*=2;
	solve(0,all-1);
	for(int i=0;i<all;i++){
		LL w=bitc(i)?MOD-1:1;
		ans+=w*modpow(2,f[i])%MOD;
		ans%=MOD;
	}ans+=MOD;
	ans%=MOD;
	printf("%d\n",(int)ans);
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<algorithm>
#include<vector>
using namespace std;
#define N 2000000
int n,a[N],sum[N];
const int MOD=7+(int)1e9;
typedef long long LL;
LL ans;
LL f[N];
void solve(int l,int r){
	if(l==r){f[l]=sum[l];return;}
	int mid=(l+r)/2;
	solve(l,mid);
	solve(mid+1,r);
	for(int i=l;i<=mid;i++)f[i]+=f[i-l+1+mid],f[i]%=MOD;
}
int bitc(int x){
	return x==0?0:bitc(x>>1)^(x&1);
}
LL modpow(LL x,LL y){
	LL ret=1;
	x%=MOD;
	for(;y;y>>=1,(x*=x)%=MOD)
		if(y&1)(ret*=x)%=MOD;
	return ret;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),sum[a[i]]++;
	int all=1;
	while(all<100000)all*=2;
	solve(0,all-1);
	for(int i=0;i<all;i++){
		LL w=bitc(i)?MOD-1:1;
		ans+=w*(modpow(2,f[i])-1)%MOD;
		ans%=MOD;
	}ans+=MOD;
	ans%=MOD;
	printf("%d\n",(int)ans);
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;

typedef long long LL;
const int N=20;
const int V=(1<<20)+10;
const int P=1000000007;
void tf(int a[],int l,int r)
{
    if(l+1==r)return ;
    int mid=(l+r)>>1,len=mid-l;
    tf(a,l,mid);tf(a,mid,r);
    for(int i=0;i<len;i++)
        a[l+i]+=a[mid+i];
}
void utf(int a[],int l,int r)
{
    if(l+1==r)return ;
    int mid=(l+r)>>1,len=mid-l;
    for(int i=0;i<len;i++)
    {
        a[l+i]-=a[mid+i];
        if(a[l+i]<0)a[l+i]+=P;
    }
    utf(a,l,mid);utf(a,mid,r);
}
int cnt[V],q[V];
int n,x,pro[V];
int pt[V];
int main()
{
    pt[0]=1;
    for(int i=1;i<(1<<N);i++)
    pt[i]=pt[i-1]*2%P;
    while(~scanf("%d",&n))
    {
        memset(cnt,0,sizeof(cnt));
        for(int i=0;i<n;i++)
        {
            scanf("%d",&x);
            cnt[x]++;
        }
        //for(int i=0;i<N;i++)
        //    for(int j=0;j<(1<<N);j++)
        //        if(((1<<i)&j)==0)
        //            cnt[j]+=cnt[(1<<i)^j];
        tf(cnt,0,(1<<N));
        for(int i=0;i<(1<<N);i++)
            pro[i]=pt[cnt[i]];
        utf(pro,0,(1<<N));
        printf("%d\n",(pro[0]+P)%P);
    }
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;

typedef long long LL;
const int N=20;
const int V=(1<<20)+10;
const int P=1000000007;
void tf(int a[],int l,int r)
{
    if(l+1==r)return ;
    int mid=(l+r)>>1,len=mid-l;
    tf(a,l,mid);tf(a,mid+1,r);
    for(int i=l;i<mid;i++)
        a[l+i]+=a[mid+i];
}
void utf(int a[],int l,int r)
{
    if(l+1==r)return ;
    int mid=(l+r)>>1,len=mid-l;
    for(int i=l;i<mid;i++)
    {
        a[l+i]-=a[mid+i];
        if(a[l+i]<0)a[l+i]+=P;
    }
    utf(a,l,mid);utf(a,mid,r);
}
int cnt[V],q[V];
int n,x,pro[V];
int pt[V];
int main()
{
    pt[0]=1;
    for(int i=1;i<(1<<N);i++)
    pt[i]=pt[i-1]*2%P;
    while(~scanf("%d",&n))
    {
        memset(cnt,0,sizeof(cnt));
        for(int i=0;i<n;i++)
        {
            scanf("%d",&x);
            cnt[x]++;
        }
        for(int i=0;i<N;i++)
            for(int j=0;j<(1<<N);j++)
                if(((1<<i)&j)==0)
                    cnt[j]+=cnt[(1<<i)^j];
        //tf(cnt,0,(1<<N));
        for(int i=0;i<(1<<N);i++)
            pro[i]=pt[cnt[i]];
        utf(pro,0,(1<<N));
        printf("%d\n",(pro[0]+P)%P);
    }
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;

typedef long long LL;
const int N=20;
const int V=(1<<20)+10;
const int P=1000000007;

int cnt[V],q[V];
int n,x,pro[V];
int pt[V];
int main()
{
    pt[0]=1;
    for(int i=1;i<(1<<N);i++)
    pt[i]=pt[i-1]*2%P;
    while(~scanf("%d",&n))
    {
        memset(cnt,0,sizeof(cnt));
        for(int i=0;i<n;i++)
        {
            scanf("%d",&x);
            cnt[x]++;
        }

        for(int i=0;i<N;i++)
            for(int j=0;j<(1<<N);j++)
                if(((1<<i)&j)==0)cnt[j]+=cnt[(1<<i)^j];

        for(int i=0;i<(1<<N);i++)pro[i]=pt[cnt[i]];

        for(int i=1;i<=(1<<N-1);i<<=1)
            for(int j=0;j<(1<<N);j+=i<<1)
                for(int k=0;k<i;k++)
                {
                    pro[j+k]-=pro[j+k+i];
                    if(pro[j+k]<0)pro[j+k]+=P;
                }

        printf("%d\n",pro[0]);
    }
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;

typedef long long LL;
const int N=20;
const int V=(1<<20)+10;
const int P=1000000007;
void tf(int a[],int l,int r)
{
    if(l+1==r)return ;
    int mid=(l+r)>>1,len=mid-l;
    tf(a,l,mid);tf(a,mid+1,r);
    for(int i=l;i<mid;i++)
        a[l+i]+=a[mid+i];
}
void utf(int a[],int l,int r)
{
    if(l+1==r)return ;
    int mid=(l+r)>>1,len=mid-l;
    for(int i=l;i<mid;i++)
    {
        a[l+i]-=a[mid+i];
        if(a[l+i]<0)a[l+i]+=P;
    }
    utf(a,l,mid);utf(a,mid,r);
}
int cnt[V],q[V];
int n,x,pro[V];
int pt[V];
int main()
{
    pt[0]=1;
    for(int i=1;i<(1<<N);i++)
    pt[i]=pt[i-1]*2%P;
    while(~scanf("%d",&n))
    {
        memset(cnt,0,sizeof(cnt));
        for(int i=0;i<n;i++)
        {
            scanf("%d",&x);
            cnt[x]++;
        }
        //for(int i=0;i<N;i++)
        //    for(int j=0;j<(1<<N);j++)
        //        if(((1<<i)&j)==0)
        //            cnt[j]+=cnt[(1<<i)^j];
        tf(cnt,0,(1<<N));
        for(int i=0;i<(1<<N);i++)
            pro[i]=pt[cnt[i]];
        utf(pro,0,(1<<N));
        printf("%d\n",(pro[0]+P)%P);
    }
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;

const int mod=100000007;
int dp[1<<20];
int pow_mod(long long a,int b)
{
    long long c=1;
    while(b)
    {
        if(b&1)c=c*a%mod;
        b>>=1;
        a=a*a%mod;
    }
    return c;
}
int main()
{
    //freopen("1.txt","r",stdin);
    int n,x;scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&x),dp[x]++;
    for(int i=0;i<20;i++)
        for(int j=0;j<(1<<20);j++)
            if((1<<i)&j)dp[(1<<i)^j]+=dp[j];
    long long ans=0;
    for(int i=0;i<(1<<20);i++)
    {
        int cnt=0;
        for(int j=0;j<20;j++)
            if((1<<j)&i)cnt++;
        if(cnt&1)ans=(ans-pow_mod(2,dp[i]))%mod;
        else ans=(ans+pow_mod(2,dp[i]))%mod;
    }
    printf("%I64d\n",(ans+mod)%mod);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;

typedef long long LL;
const int N=20;
const int V=(1<<20)+10;
const int P=1000000007;
int Pow(int x,int y)
{
    int ret=1;
    while(y)
    {
        if(y&1)ret=(LL)ret*x%P;
        x=(LL)x*x%P;y/=2;
    }
    return ret;
}
void utf(int *a,int l,int r)
{
    if(l+1!=r)
    {
        int mid=(l+r)/2;
        for(int i=0;i<mid-l;i++)
        {
            a[l+i]-=a[mid+i];
            if(a[l+i]<0)a[l+i]+=P;
        }
        utf(a,l,mid);
        utf(a,mid,r);
    }
}
void tf(int *a,int l,int r)
{
    if(l+1!=r)
    {
        int mid=(l+r)/2;
        tf(a,l,mid);
        tf(a,mid,r);
        for(int i=0;i<mid-l;i++)
        {
            a[l+i]+=a[mid+i];
            if(a[l+i]>=P)a[i+l]-=P;
        }
    }
}
int cnt[V],q[V];
int n,x,pro[V];
int pt[V];
int main()
{
    pt[0]=1;
    for(int i=1;i<(1<<N);i++)
    pt[i]=pt[i-1]*2%P;
    while(~scanf("%d",&n))
    {
        memset(cnt,0,sizeof(cnt));
        for(int i=0;i<n;i++)
        {
            scanf("%d",&x);
            cnt[x]++;
        }
        for(int i=0;i<N;i++)
            for(int j=0;j<(1<<N);j++)
                if(((1<<i)&j)==0)cnt[j]+=cnt[(1<<i)^j];
        //tf(cnt,0,(1<<N));
        for(int i=0;i<(1<<N);i++)
            pro[i]=pt[cnt[i]];
        utf(pro,0,(1<<N));
        printf("%d\n",pro[0]);
    }
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;

typedef long long LL;
const int N=20;
const int V=(1<<20)+10;
const int P=1000000007;
void tf(int a[],int l,int r)
{
    if(l+1==r)return ;
    int mid=(l+r)>>1,len=mid-l;
    tf(a,l,mid);tf(a,mid,r);
    for(int i=l;i<mid;i++)
        a[l+i]+=a[mid+i];
}
void utf(int a[],int l,int r)
{
    if(l+1==r)return ;
    int mid=(l+r)>>1,len=mid-l;
    for(int i=l;i<mid;i++)
    {
        a[l+i]-=a[mid+i];
        if(a[l+i]<0)a[l+i]+=P;
    }
    utf(a,l,mid);utf(a,mid,r);
}
int cnt[V],q[V];
int n,x,pro[V];
int pt[V];
int main()
{
    pt[0]=1;
    for(int i=1;i<(1<<N);i++)
    pt[i]=pt[i-1]*2%P;
    while(~scanf("%d",&n))
    {
        memset(cnt,0,sizeof(cnt));
        for(int i=0;i<n;i++)
        {
            scanf("%d",&x);
            cnt[x]++;
        }
        //for(int i=0;i<N;i++)
        //    for(int j=0;j<(1<<N);j++)
        //        if(((1<<i)&j)==0)
        //            cnt[j]+=cnt[(1<<i)^j];
        tf(cnt,0,(1<<N));
        for(int i=0;i<(1<<N);i++)
            pro[i]=pt[cnt[i]];
        utf(pro,0,(1<<N));
        printf("%d\n",(pro[0]+P)%P);
    }
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;

typedef long long LL;
const int N=20;
const int V=(1<<20)+10;
const int P=1000000007;

int cnt[V],q[V];
int n,x,pro[V];
int pt[V];
int main()
{
    pt[0]=1;
    for(int i=1;i<(1<<N);i++)
    pt[i]=pt[i-1]*2%P;
    while(~scanf("%d",&n))
    {
        memset(cnt,0,sizeof(cnt));
        for(int i=0;i<n;i++)
        {
            scanf("%d",&x);
            cnt[x]++;
        }
        for(int i=0;i<N;i++)
            for(int j=0;j<(1<<N);j++)
                if(((1<<i)&j)==0)
                    cnt[j]+=cnt[(1<<i)^j];
        for(int i=0;i<(1<<N);i++)
            pro[i]=pt[cnt[i]];
        for(int i=1;i<=(1<<N-1);i<<=1)
            for(int j=0;j<(1<<N);j+=i<<1)
                for(int k=0;k<i;k++)
                {
                    pro[j+k]-=pro[j+k+i];
                    if(pro[j+k]<0)pro[j+k]+=P;
                }
        printf("%d\n",(pro[0]+P)%P);
    }
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;

typedef long long LL;
const int N=20;
const int V=(1<<20)+10;
const int P=1000000007;
void tf(int a[],int l,int r)
{
    if(l+1==r)return ;
    int mid=(l+r)>>1,len=mid-l;
    tf(a,l,mid);tf(a,mid,r);
    for(int i=0;i<len;i++)
        a[l+i]+=a[mid+i];
}
void utf(int a[],int l,int r)
{
    if(l+1==r)return ;
    int mid=(l+r)>>1,len=mid-l;
    for(int i=0;i<len;i++)
    {
        a[l+i]-=a[mid+i];
        if(a[l+i]<0)a[l+i]+=P;
    }
    utf(a,l,mid);utf(a,mid,r);
}
int cnt[V],q[V];
int n,x,pro[V];
int pt[V];
int main()
{
    pt[0]=1;
    for(int i=1;i<(1<<N);i++)
    pt[i]=pt[i-1]*2%P;
    while(~scanf("%d",&n))
    {
        memset(cnt,0,sizeof(cnt));
        for(int i=0;i<n;i++)
        {
            scanf("%d",&x);
            cnt[x]++;
        }
        tf(cnt,0,(1<<N));
        for(int i=0;i<(1<<N);i++)
            pro[i]=pt[cnt[i]];
        utf(pro,0,(1<<N));
        printf("%d\n",(pro[0]+P)%P);
    }
}


// In the Name of Allah
// AD13

#include <map>
#include <set>
#include <string>
#include <vector>
#include <numeric>
#include <iostream>
#include <algorithm>
using namespace std;

typedef vector<int> VI;
typedef long long ll;
// typedef unsigned long long  ull;
typedef pair<int, int> pii;
// typedef pair<double, double> pdd;
#define MP make_pair
/*-------------------------------------------------------------------------------------*/

int n;
VI vx;

VI cntK(int k)
{
    VI cnt(n + 1);
    int lastInd = n - 1;
    for (int i = n - 1; i >= 0; i--)
    {
        cnt[i] = cnt[i + 1] + 1;

        while (lastInd > i)
        {
            if (vx[lastInd] - vx[i] > k)
            {
                cnt[i]--;
                lastInd--;
            }
            else break;
        }
    }

    return cnt;
}

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

        vx.resize(n);
        for (int i = 0; i < n; ++i)  cin >> vx[i];

        int tmp;
        for (int i = 0; i < n; ++i) cin >> tmp;

        sort(vx.begin(), vx.end());

        VI cnts = cntK(k + k + 1);

        int ans = *max_element(cnts.begin(), cnts.end());

        cnts = cntK(k);

        set<int> maxInds;
        int mx1 = max_element(cnts.begin(), cnts.end()) - cnts.begin();
        maxInds.insert(mx1);

        for (int k = 0; k < 2; k++)
        {
            VI oldInds;
            for (int i : maxInds) oldInds.push_back(i);

            for (int i = 0; i < oldInds.size(); i++)
            {
                int st = 0;
                if (i > 0) st = oldInds[i - 1];

                int mx1 = oldInds[i];
                if (mx1 > st) {
                    maxInds.insert(max_element(cnts.begin() + st, cnts.begin() + mx1) - cnts.begin());
                }
            }
            if (!oldInds.empty() && (*oldInds.rend()) < n - 1) {
                maxInds.insert(max_element(cnts.begin() + *oldInds.rend(), cnts.end()) - cnts.begin());
            }

        }

        for (int maxInd1 : maxInds)
        {
            int ans21 = cnts[maxInd1];

            int ans22 = 0;
            for (int ind2 = maxInd1 + 1; ind2 < n; ind2++)
            {
                if (vx[ind2] - vx[maxInd1] <= k) continue;

                ans22 = max(ans22, cnts[ind2]);
            }
            ans = max(ans, ans21 + ans22);

            ans22 = 0;
            for (int ind2 = 0; ind2 < maxInd1; ind2++)
            {
                if (vx[maxInd1] - vx[ind2] <= k) break;

                ans22 = max(ans22, cnts[ind2]);
            }
            ans = max(ans, ans21 + ans22);
        }

        // cout << " -> ";
        cout << ans << endl;
    }

    return 0;
}
/*

*/


// In the Name of Allah
// AD13

#include <map>
#include <set>
#include <string>
#include <vector>
#include <numeric>
#include <iostream>
#include <algorithm>
using namespace std;

typedef vector<int> VI;
typedef long long ll;
// typedef unsigned long long  ull;
typedef pair<int, int> pii;
// typedef pair<double, double> pdd;
#define MP make_pair
/*-------------------------------------------------------------------------------------*/

int n;
VI vx;

VI cntK(int k)
{
    VI cnt(n + 1);
    int lastInd = n - 1;
    for (int i = n - 1; i >= 0; i--)
    {
        cnt[i] = cnt[i + 1] + 1;

        while (lastInd > i)
        {
            if (vx[lastInd] - vx[i] > k)
            {
                cnt[i]--;
                lastInd--;
            }
            else break;
        }
    }

    return cnt;
}

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

        vx.resize(n);
        for (int i = 0; i < n; ++i)  cin >> vx[i];

        int tmp;
        for (int i = 0; i < n; ++i) cin >> tmp;

        sort(vx.begin(), vx.end());

        VI cnts = cntK(k + k + 1);

        int ans = *max_element(cnts.begin(), cnts.end());

        cnts = cntK(k);

        vector<pii> maxCnts;
        for (int i = 0; i < n; i++)
            maxCnts.push_back(MP(cnts[i], i));
        sort(maxCnts.rbegin(), maxCnts.rend());

        VI maxInds;
        // int mx1 = max_element(cnts.begin(), cnts.end()) - cnts.begin();
        // maxInds.insert(mx1);
        for (int k = 0; k < min(n, 100); k++) maxInds.push_back(maxCnts[k].second);

        for (int maxInd1 : maxInds)
        {
            int ans21 = cnts[maxInd1];

            int ans22 = 0;
            for (int ind2 = maxInd1 + 1; ind2 < n; ind2++)
            {
                if (vx[ind2] - vx[maxInd1] <= k) continue;

                ans22 = max(ans22, cnts[ind2]);
            }
            ans = max(ans, ans21 + ans22);

            ans22 = 0;
            for (int ind2 = 0; ind2 < maxInd1; ind2++)
            {
                if (vx[maxInd1] - vx[ind2] <= k) break;

                ans22 = max(ans22, cnts[ind2]);
            }
            ans = max(ans, ans21 + ans22);
        }

        // cout << " -> ";
        cout << ans << endl;
    }

    return 0;
}
/*

*/


#include <bits/stdc++.h>

#define debug(x) cout << #x << " ---  " << x << endl
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define pb push_back

using namespace std;

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

    long long t;
    cin >> t;
    while (t--) {
        long long n, k;
        cin >> n >> k;
        vector <long long> v(n), tr(n);
        for (long long i = 0; i < n; ++i) {
            cin >> v[i];
        }
        for (long long i = 0; i < n; ++i)
            cin >> tr[i];
        sort(all(v));
        long long sum = 0;
        vector <long long> pref(n, 0), suf(n, 0);
        long long left = 0;
        long long cur = 0;
        for (long long i = 0; i < n; ++i) {
            if (v[i] - v[left] <= k) {
                cur++;
            }
            while (v[i] - v[left] > k)
                left++, cur--;
            if (i)
            pref[i] = max(pref[i-1], cur);
            else
                pref[i] = cur;
        }
        cur = 0;
        long long right = n - 1;
        for (long long i = n - 1; i >= 0; --i) {
            if (v[right] - v[i] <= k)
                cur++;
            while (v[right] - v[i] > k)
                right--, cur--;
            if (i + 1 < n)
            suf[i] = max(suf[i+1], cur);
            else
                suf[i] = cur;
        }
        left = 0, cur = 1;
        long long ans = 1;
        if (n > 1)
            ans += suf[1];
        for (long long i = 1; i < n; ++i) {
            if (v[i] - v[left] <= k) {
                cur++;
            }
            while (v[i] - v[left] > k)
                left++, cur--;
            long long temp1 = 0, temp2;
            if (left)
                temp1 += pref[left - 1];
            if (i + 1 < n)
                temp2 += suf[i + 1];
            ans = max(ans, max(temp1, temp2) + cur);
        }
        cout << ans << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>

#define debug(x) cout << #x << " ---  " << x << endl
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define pb push_back

using namespace std;

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

    long long t;
    cin >> t;
    while (t--) {
        long long n, k;
        cin >> n >> k;
        vector <long long> v(n), tr(n);
        for (long long i = 0; i < n; ++i) {
            cin >> v[i];
        }
        for (long long i = 0; i < n; ++i)
            cin >> tr[i];
        sort(all(v));
        long long sum = 0;
        vector <long long> pref(n, 0), suf(n, 0);
        long long left = 0;
        long long cur = 0;
        for (long long i = 0; i < n; ++i) {
            if (v[i] - v[left] <= k) {
                cur++;
            }
            while (v[i] - v[left] > k)
                left++, cur--;
            if (i)
                pref[i] = max(pref[i-1], cur);
            else
                pref[i] = cur;
        }
        cur = 0;
        long long right = n - 1;
        for (long long i = n - 1; i >= 0; --i) {
            if (v[right] - v[i] <= k)
                cur++;
            while (v[right] - v[i] > k)
                right--, cur--;
            if (i + 1 < n)
                suf[i] = max(suf[i+1], cur);
            else
                suf[i] = cur;
        }
        left = 0, cur = 1;
        long long ans = 1;
        if (n > 1)
            ans += suf[1];
        for (long long i = 1; i < n; ++i) {
            if (v[i] - v[left] <= k) {
                cur++;
            }
            while (v[i] - v[left] > k)
                left++, cur--;
            long long temp1 = 0, temp2 = 0;
            if (left)
                temp1 += pref[left - 1];
            if (i + 1 < n)
                temp2 += suf[i + 1];
            ans = max(ans, max(temp1, temp2) + cur);
        }
        cout << ans << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>

#define debug(x) cout << #x << " ---  " << x << endl
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define pb push_back

using namespace std;

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

    long long t;
    cin >> t;
    while (t--) {
        long long n, k;
        cin >> n >> k;
        vector <long long> v(n), tr(n);
        for (long long i = 0; i < n; ++i) {
            cin >> v[i];
        }
        for (long long i = 0; i < n; ++i)
            cin >> tr[i];
        sort(all(v));
        long long sum = 0;
        vector <long long> pref(n, 0), suf(n, 0);
        long long left = 0;
        long long cur = 0;
        for (long long i = 0; i < n; ++i) {
            while (v[i] - v[left] > k)
                left++, cur--;
            if (v[i] - left <= k)
                cur++;
            if (i)
                pref[i] = max(pref[i-1], cur);
            else
                pref[i] = cur;
        }
        cur = 0;
        long long right = n - 1;
        for (long long i = n - 1; i >= 0; --i) {

            while (v[right] - v[i] > k)
                right--, cur--;
            if (v[right] - v[i] <= k)
                cur++;
            if (i + 1 < n)
                suf[i] = max(suf[i+1], cur);
            else
                suf[i] = cur;
        }
        left = 0, cur = 1;
        long long ans = 1;
        if (n > 1)
            ans += suf[1];
        for (long long i = 1; i < n; ++i) {
            if (v[i] - v[left] <= k) {
                cur++;
            }
            while (v[i] - v[left] > k)
                left++, cur--;
            long long temp1 = 0, temp2 = 0;
            if (left)
                temp1 += pref[left - 1];
            if (i + 1 < n)
                temp2 += suf[i + 1];
            ans = max(ans, max(temp1, temp2) + cur);
        }
        cout << ans << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>

#define debug(x) cout << #x << " ---  " << x << endl
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define pb push_back

using namespace std;

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

    long long t;
    cin >> t;
    while (t--) {
        long long n, k;
        cin >> n >> k;
        vector <long long> v(n), tr(n);
        for (long long i = 0; i < n; ++i) {
            cin >> v[i];
        }
        for (long long i = 0; i < n; ++i)
            cin >> tr[i];
        sort(all(v));
        long long sum = 0;
        vector <long long> pref(n, 0), suf(n, 0);
        long long left = 0;
        long long cur = 0;
        for (long long i = 0; i < n; ++i) {
            while (v[i] - v[left] > k)
                left++, cur--;
            if (v[i] - left <= k)
                cur++;
            if (i)
                pref[i] = max(pref[i-1], cur);
            else
                pref[i] = cur;
        }
        cur = 0;
        long long right = n - 1;
        for (long long i = n - 1; i >= 0; --i) {

            while (v[right] - v[i] > k)
                right--, cur--;
            if (v[right] - v[i] <= k)
                cur++;
            if (i + 1 < n)
                suf[i] = max(suf[i+1], cur);
            else
                suf[i] = cur;
        }
        left = 0, cur = 1;
        long long ans = 1;
        if (n > 1)
            ans += suf[1];
        for (long long i = 1; i < n; ++i) {

            while (v[i] - v[left] > k)
                left++, cur--;
            if (v[i] - v[left] <= k) {
                cur++;
            }
            long long temp1 = 0, temp2 = 0;
            if (left)
                temp1 += pref[left - 1];
            if (i + 1 < n)
                temp2 += suf[i + 1];
            ans = max(ans, max(temp1, temp2) + cur);
        }
        cout << ans << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>

#define debug(x) cout << #x << " ---  " << x << endl
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define pb push_back

using namespace std;

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

    long long t;
    cin >> t;
    while (t--) {
        long long n, k;
        cin >> n >> k;
        vector <long long> v(n), tr(n);
        for (long long i = 0; i < n; ++i) {
            cin >> v[i];
        }
        for (long long i = 0; i < n; ++i)
            cin >> tr[i];
        sort(all(v));
        long long sum = 0;
        vector <long long> pref(n, 0), suf(n, 0);
        long long left = 0;
        long long cur = 0;
        for (long long i = 0; i < n; ++i) {
            if (v[i] - v[left] <= k) {
                cur++;
            }
            while (v[i] - v[left] > k)
                left++, cur--;
            if (i)
            pref[i] = max(pref[i-1], cur);
            else
                pref[i] = cur;
        }
        cur = 0;
        long long right = n - 1;
        for (long long i = n - 1; i >= 0; --i) {
            if (v[right] - v[i] <= k)
                cur++;
            while (v[right] - v[i] > k)
                right--, cur--;
            if (i + 1 < n)
            suf[i] = max(suf[i+1], cur);
            else
                suf[i] = cur;
        }
        left = 0, cur = 1;
        long long ans = 1;
        for (long long i = 0; i < n - 1; ++i) {
            ans = max(ans, pref[i] + suf[i+1]);
        }
        cout << ans << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>

#define debug(x) cout << #x << " ---  " << x << endl
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define pb push_back

using namespace std;

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

    long long t;
    cin >> t;
    while (t--) {
        long long n, k;
        cin >> n >> k;
        vector <long long> v(n), tr(n);
        for (long long i = 0; i < n; ++i) {
            cin >> v[i];
        }
        for (long long i = 0; i < n; ++i)
            cin >> tr[i];
        sort(all(v));
        long long sum = 0;
        vector <long long> pref(n, 0), suf(n, 0);
        long long left = 0;
        long long cur = 0;
        for (long long i = 0; i < n; ++i) {
            if (v[i] - v[left] <= k) {
                cur++;
            }
            while (v[i] - v[left] > k)
                left++, cur--;
            if (i)
            pref[i] = max(pref[i-1], cur);
            else
                pref[i] = cur;
        }
        cur = 0;
        long long right = n - 1;
        for (long long i = n - 1; i >= 0; --i) {
            if (v[right] - v[i] <= k)
                cur++;
            while (v[right] - v[i] > k)
                right--, cur--;
            if (i + 1 < n)
            suf[i] = max(suf[i+1], cur);
            else
                suf[i] = cur;
        }
        left = 0, cur = 1;
        long long ans = 1;
        for (long long i = 1; i < n; ++i) {
            if (v[i] - v[left] <= k) {
                cur++;
            }
            while (v[i] - v[left] > k)
                left++, cur--;
            long long temp = 0;
            if (left)
                temp += pref[left - 1];
            if (i + 1 < n)
                temp += suf[i + 1];
            ans = max(ans, temp + cur);
        }
        cout << ans << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>

#define debug(x) cout << #x << " ---  " << x << endl
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define pb push_back

using namespace std;

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

    long long t;
    cin >> t;
    while (t--) {
        long long n, k;
        cin >> n >> k;
        vector <long long> v(n), tr(n);
        for (long long i = 0; i < n; ++i) {
            cin >> v[i];
        }
        for (long long i = 0; i < n; ++i)
            cin >> tr[i];
        sort(all(v));
        long long sum = 0;
        vector <long long> pref(n, 0), suf(n, 0);
        long long left = 0;
        long long cur = 0;
        for (long long i = 0; i < n; ++i) {
            if (v[i] - v[left] <= k) {
                cur++;
            }
            while (v[i] - v[left] > k)
                left++, cur--;
            if (i)
            pref[i] = max(pref[i-1], cur);
            else
                pref[i] = cur;
        }
        cur = 0;
        long long right = n - 1;
        for (long long i = n - 1; i >= 0; --i) {
            if (v[right] - v[i] <= k)
                cur++;
            while (v[right] - v[i] > k)
                right--, cur--;
            if (i + 1 < n)
            suf[i] = max(suf[i+1], cur);
            else
                suf[i] = cur;
        }
        left = 0, cur = 1;
        long long ans = 1;
        if (n > 1)
            ans += suf[1];
        for (long long i = 1; i < n; ++i) {
            if (v[i] - v[left] <= k) {
                cur++;
            }
            while (v[i] - v[left] > k)
                left++, cur--;
            long long temp = 0;
            if (left)
                temp += pref[left - 1];
            if (i + 1 < n)
                temp += suf[i + 1];
            ans = max(ans, temp + cur);
        }
        cout << ans << '\n';
    }
    return 0;
}


// Example program
#include <iostream>
#include <sstream>
#include <string>
#include <set>
#include <vector>
#include<cmath>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
    size_t t;
    cin >> t;
    for (size_t j = 0; j < t; ++j)
    {
        size_t n, k;
        cin >> n >> k;
        map<size_t, size_t> dot_count;
        for (size_t i = 0; i < n; ++i)
        {
            size_t x;
            cin >> x;
            ++dot_count[x];
        }
        for (size_t i = 0; i < n; ++i)
        {
            size_t x;
            cin >> x;
        }
        if (dot_count.size() <= 2 || dot_count.rbegin()->first - dot_count.begin()->first <= 2*k)
        {
            cout << n << endl;
            continue;
        }
        map<size_t, size_t> saved_count;
        auto begin = dot_count.begin();
        auto end = dot_count.begin();
        auto last_intersect = dot_count.begin();
        size_t i = 0;
        size_t prev_max = 0, ans = 0;
        size_t sum = 0;
        for (; end != dot_count.end(); ++begin)
        {
            auto x_begin = begin->first;
            for (; end != dot_count.end() && x_begin + k >= end->first; ++end)
            {
                sum += end->second;
            }

            saved_count[x_begin] = sum;
            size_t cur_max_sum = sum;
            if (x_begin >= last_intersect->first + k)
            {
                if (saved_count[last_intersect->first] > prev_max)
                {
                    prev_max = saved_count[last_intersect->first];
                }
                while (last_intersect->first + k <= x_begin)
                {
                    ++last_intersect;
                }
            }
            if (sum + prev_max > ans)
                ans = sum + prev_max;
            sum -= begin->second;
        }
        cout << ans << endl;
    }
}


// Example program
#include <iostream>
#include <sstream>
#include <string>
#include <set>
#include <vector>
#include<cmath>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
    size_t t;
    cin >> t;
    for (size_t j = 0; j < t; ++j)
    {
        size_t n, k;
        cin >> n >> k;
        map<size_t, size_t> dot_count;
        for (size_t i = 0; i < n; ++i)
        {
            size_t x;
            cin >> x;
            ++dot_count[x];
        }
        for (size_t i = 0; i < n; ++i)
        {
            size_t x;
            cin >> x;
        }
        if (dot_count.size() <= 2 || dot_count.rbegin()->first - dot_count.begin()->first <= 2*k)
        {
            cout << n << endl;
            continue;
        }
        map<size_t, size_t> saved_count;
        auto begin = dot_count.begin();
        auto end = dot_count.begin();
        auto last_intersect = dot_count.begin();
        size_t prev_max = 0, ans = 0;
        size_t sum = 0;
        for (; end != dot_count.end(); ++begin)
        {
            auto x_begin = begin->first;
            for (; end != dot_count.end() && x_begin + k >= end->first; ++end)
            {
                sum += end->second;
            }

            saved_count[x_begin] = sum;
            if (x_begin > last_intersect->first + k)
            {
                do
                {
                    if (saved_count[last_intersect->first] > prev_max)
                    {
                        prev_max = saved_count[last_intersect->first];
                    }
                    ++last_intersect;
                } while (last_intersect->first + k < x_begin);
            }
            if (sum + prev_max > ans)
                ans = sum + prev_max;
            sum -= begin->second;
        }
        cout << ans << endl;
    }
}


// Example program
#include <iostream>
#include <sstream>
#include <string>
#include <set>
#include <vector>
#include<cmath>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
    size_t t;
    cin >> t;
    for (size_t j = 0; j < t; ++j)
    {
        size_t n, k;
        cin >> n >> k;
        map<size_t, size_t> dot_count;
        for (size_t i = 0; i < n; ++i)
        {
            size_t x;
            cin >> x;
            ++dot_count[x];
        }
        for (size_t i = 0; i < n; ++i)
        {
            size_t x;
            cin >> x;
        }
        if (dot_count.size() <= 2 || dot_count.rbegin()->second - dot_count.begin()->second <= 2*k)
        {
            cout << n << endl;
            continue;
        }
        map<size_t, size_t> saved_count;
        auto begin = dot_count.begin();
        auto end = dot_count.begin();
        auto last_intersect = dot_count.begin();
        size_t i = 0;
        size_t prev_max = 0, ans = 0;
        size_t sum = 0;
        for (; end != dot_count.end(); ++begin)
        {
            auto x_begin = begin->first;
            for (; end != dot_count.end() && x_begin + k >= end->first; ++end)
            {
                sum += end->second;
            }

            saved_count[x_begin] = sum;
            size_t cur_max_sum = sum;
            if (x_begin >= last_intersect->first + k)
            {
                if (saved_count[last_intersect->first] > prev_max)
                {
                    prev_max = saved_count[last_intersect->first];
                }
                while (last_intersect->first + k <= x_begin)
                {
                    ++last_intersect;
                }
            }
            if (sum + prev_max > ans)
                ans = sum + prev_max;
            sum -= begin->second;
        }
        cout << ans << endl;
    }
}


// Example program
#include <iostream>
#include <sstream>
#include <string>
#include <set>
#include <vector>
#include<cmath>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
    size_t t;
    cin >> t;
    for (size_t j = 0; j < t; ++j)
    {
        size_t n, k;
        cin >> n >> k;
        map<size_t, size_t> dot_count;
        for (size_t i = 0; i < n; ++i)
        {
            size_t x;
            cin >> x;
            ++dot_count[x];
        }
        for (size_t i = 0; i < n; ++i)
        {
            size_t x;
            cin >> x;
        }
        if (dot_count.size() <= 2 || dot_count.rbegin()->first - dot_count.begin()->first <= 2*k)
        {
            cout << n << endl;
            continue;
        }
        map<size_t, size_t> saved_count;
        map<size_t, size_t> rsaved_count;
        auto begin = dot_count.begin();
        auto end = dot_count.begin();
        auto end_both = dot_count.begin();
        auto last_intersect = dot_count.begin();
        size_t prev_max = 0, ans = 0;
        size_t sum = 0, sum_both = 0;
        for (; end != dot_count.end(); ++begin)
        {
            auto x_begin = begin->first;
            for (; end != dot_count.end() && x_begin + k >= end->first; ++end)
            {
                sum += end->second;
            }
            for (; end_both != dot_count.end() && x_begin + 2 * k >= end_both->first; ++end_both)
            {
                sum_both += end_both->second;
            }

            saved_count[x_begin] = sum;
            if (x_begin > last_intersect->first + k)
            {
                do
                {
                    if (saved_count[last_intersect->first] > prev_max)
                    {
                        prev_max = saved_count[last_intersect->first];
                    }
                    ++last_intersect;
                } while (last_intersect->first + k < x_begin);
            }
            if (sum + prev_max > ans)
                ans = sum + prev_max;
            if (sum_both > ans)
                ans = sum_both;
            sum -= begin->second;
            sum_both -= begin->second;
        }
        cout << ans << endl;
    }
}


// Example program
#include <iostream>
#include <sstream>
#include <string>
#include <set>
#include <vector>
#include<cmath>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
    size_t t;
    cin >> t;
    for (size_t j = 0; j < t; ++j)
    {
        size_t n, k;
        cin >> n >> k;
        map<size_t, size_t> dot_count;
        for (size_t i = 0; i < n; ++i)
        {
            size_t x;
            cin >> x;
            ++dot_count[x];
        }
        for (size_t i = 0; i < n; ++i)
        {
            size_t x;
            cin >> x;
        }
        if (dot_count.size() <= 2 || dot_count.rbegin()->first - dot_count.begin()->first <= 2*k)
        {
            cout << n << endl;
            continue;
        }
        map<size_t, size_t> saved_count;
        auto begin = dot_count.begin();
        auto end = dot_count.begin();
        auto end_both = dot_count.begin();
        auto last_intersect = dot_count.begin();
        size_t prev_max = 0, ans = 0;
        size_t sum = 0, sum_both = 0;
        for (; end != dot_count.end(); ++begin)
        {
            auto x_begin = begin->first;
            for (; end != dot_count.end() && x_begin + k >= end->first; ++end)
            {
                sum += end->second;
            }
            for (; end_both != dot_count.end() && x_begin + 2 * k >= end_both->first; ++end_both)
            {
                sum_both += end->second;
            }

            saved_count[x_begin] = sum;
            if (x_begin >= last_intersect->first + k)
            {
                do
                {
                    if (saved_count[last_intersect->first] > prev_max)
                    {
                        prev_max = saved_count[last_intersect->first];
                    }
                    ++last_intersect;
                } while (last_intersect->first + k <= x_begin);
            }
            if (sum + prev_max > ans)
                ans = sum + prev_max;
            if (sum_both > ans)
                ans = sum_both;
            sum -= begin->second;
            sum_both -= begin->second;
        }
        cout << ans << endl;
    }
}


// Example program
#include <iostream>
#include <sstream>
#include <string>
#include <set>
#include <vector>
#include<cmath>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
    size_t t;
    cin >> t;
    for (size_t j = 0; j < t; ++j)
    {
        size_t n, k;
        cin >> n >> k;
        map<size_t, size_t> dot_count;
        for (size_t i = 0; i < n; ++i)
        {
            size_t x;
            cin >> x;
            ++dot_count[x];
        }
        for (size_t i = 0; i < n; ++i)
        {
            size_t x;
            cin >> x;
        }
        if (dot_count.size() <= 2 || dot_count.rbegin()->first - dot_count.begin()->first <= 2*k)
        {
            cout << n << endl;
            continue;
        }
        map<size_t, size_t> saved_count;
        auto begin = dot_count.begin();
        auto end = dot_count.begin();
        auto end_both = dot_count.begin();
        auto last_intersect = dot_count.begin();
        size_t prev_max = 0, ans = 0;
        size_t sum = 0, sum_both = 0;
        for (; end != dot_count.end(); ++begin)
        {
            auto x_begin = begin->first;
            for (; end != dot_count.end() && x_begin + k >= end->first; ++end)
            {
                sum += end->second;
            }
            for (; end_both != dot_count.end() && x_begin + 2 * k >= end_both->first; ++end_both)
            {
                sum_both += end->second;
            }

            saved_count[x_begin] = sum;
            size_t cur_max_sum = sum;
            if (x_begin >= last_intersect->first + k)
            {
                do
                {
                    ++last_intersect;
                } while (last_intersect->first + k <= x_begin);
                if (saved_count[last_intersect->first] > prev_max)
                {
                    prev_max = saved_count[last_intersect->first];
                }
            }
            if (sum + prev_max > ans)
                ans = sum + prev_max;
            if (sum_both > ans)
                ans = sum_both;
            sum -= begin->second;
            sum_both -= begin->second;
        }
        cout << ans << endl;
    }
}


// Example program
#include <iostream>
#include <sstream>
#include <string>
#include <set>
#include <vector>
#include<cmath>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
    size_t t;
    cin >> t;
    for (size_t j = 0; j < t; ++j)
    {
        size_t n, k;
        cin >> n >> k;
        map<size_t, size_t> dot_count;
        for (size_t i = 0; i < n; ++i)
        {
            size_t x;
            cin >> x;
            ++dot_count[x];
        }
        for (size_t i = 0; i < n; ++i)
        {
            size_t x;
            cin >> x;
        }
        if (dot_count.size() <= 2 || dot_count.rbegin()->first - dot_count.begin()->first <= 2*k)
        {
            cout << n << endl;
            continue;
        }
        map<size_t, size_t> saved_count;
        map<size_t, size_t> rsaved_count;
        auto begin = dot_count.begin();
        auto end = dot_count.begin();
        auto end_both = dot_count.begin();
        auto last_intersect = dot_count.begin();
        size_t prev_max = 0, ans = 0;
        size_t sum = 0, sum_both = 0;
        for (; end != dot_count.end(); ++begin)
        {
            auto x_begin = begin->first;
            for (; end != dot_count.end() && x_begin + k >= end->first; ++end)
            {
                sum += end->second;
            }
            for (; end_both != dot_count.end() && x_begin + 2 * k >= end_both->first; ++end_both)
            {
                sum_both += end_both->second;
            }

            saved_count[x_begin] = sum;
            if (x_begin >= last_intersect->first + k)
            {
                do
                {
                    if (saved_count[last_intersect->first] > prev_max)
                    {
                        prev_max = saved_count[last_intersect->first];
                    }
                    ++last_intersect;
                } while (last_intersect->first + k <= x_begin);
            }
            if (sum + prev_max > ans)
                ans = sum + prev_max;
            if (sum_both > ans)
                ans = sum_both;
            sum -= begin->second;
            sum_both -= begin->second;
        }
        cout << ans << endl;
    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define readl(_s) getline(cin, (_s));
#define boost() cin.tie(0); cin.sync_with_stdio(0)
#define tree vojpwoekjf
#define ALL(id) id, 1, 1, sz

const int MN = 200005;

int n, k, x[MN], y[MN], tree[2][MN * 4], lazy[2][MN * 8], reset[2][MN * 8];
pii segs[MN];

inline void updLazy(int id, int i) {
    if (reset[id][i]) {
        tree[id][i] = lazy[id][i] = 0;
        reset[id][i << 1] = 1;
        reset[id][i << 1 | 1] = 1;
        reset[id][i] = 0;
    }
    if (lazy[id][i]) {
        tree[id][i] += lazy[id][i];
        lazy[id][i << 1] += lazy[id][i];
        lazy[id][i << 1 | 1] += lazy[id][i];
        lazy[id][i] = 0;
    }
}

int query(int id, int i, int l, int r, int ql, int qr) {
    updLazy(id, i);
    if (l >= ql && r <= qr) return tree[id][i];
    if (r < ql || l > qr) return 0;
    int mid = (l + r) >> 1;
    return max(query(id, i << 1, l, mid, ql, qr), query(id, i << 1 | 1, mid + 1, r, ql, qr));
}

int update(int id, int i, int l, int r, int ql, int qr, int v) {
    updLazy(id, i);
    if (l >= ql && r <= qr) {
        lazy[id][i] += v;
        return tree[id][i] + v;
    }
    if (r < ql || l > qr) return tree[id][i];
    int mid = (l + r) >> 1;
    return tree[id][i] = max(update(id, i << 1, l, mid, ql, qr, v), update(id, i << 1 | 1, mid + 1, r, ql, qr, v));
}

int32_t main() {
    boost();

    int t;
    cin >> t;
    while (t--) {
        vector<int> v;
        cin >> n >> k;
        for (int i = 1; i <= n; i++) {
            cin >> x[i];
            segs[i] = {x[i], x[i] + k};
            v.push_back(segs[i].f);
            v.push_back(segs[i].s);
        }
        for (int i = 1; i <= n; i++) cin >> y[i];

        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        sort(segs + 1, segs + n + 1);
        int sz = v.size();
        for (int i = 1; i <= n; i++) {
            segs[i].f = lower_bound(v.begin(), v.end(), segs[i].f) - v.begin() + 1;
            segs[i].s = lower_bound(v.begin(), v.end(), segs[i].s) - v.begin() + 1;
        }
        for (int i = 1; i <= n; i++) update(ALL(1), segs[i].f, segs[i].s, 1);
        int best = query(ALL(1), 1, sz);
        for (int i = 1; i <= n; i++) {
            update(ALL(1), segs[i].f, segs[i].s, -1);
            update(ALL(0), segs[i].f, segs[i].s, 1);
            best = max(best, query(ALL(0), 1, sz) + query(ALL(1), 1, sz));
        }
        printf("%lld\n", best);
        reset[0][1] = reset[1][1] = 1;
        update(ALL(1), 1, sz, 0);
        update(ALL(0), 1, sz, 0);
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define readl(_s) getline(cin, (_s));
#define boost() cin.tie(0); cin.sync_with_stdio(0)
#define tree vojpwoekjf
#define ALL(id) id, 1, 1, sz

const int MN = 200005;

int n, k, x[MN], y[MN], tree[2][MN * 30], lazy[2][MN * 30];
pii segs[MN];

inline void updLazy(int id, int i) {
    if (lazy[id][i]) {
        tree[id][i] += lazy[id][i];
        lazy[id][i << 1] += lazy[id][i];
        lazy[id][i << 1 | 1] += lazy[id][i];
        lazy[id][i] = 0;
    }
}

int query(int id, int i, int l, int r, int ql, int qr) {
    updLazy(id, i);
    if (l >= ql && r <= qr) return tree[id][i];
    if (r < ql || l > qr) return 0;
    int mid = (l + r) >> 1;
    return max(query(id, i << 1, l, mid, ql, qr), query(id, i << 1 | 1, mid + 1, r, ql, qr));
}

int update(int id, int i, int l, int r, int ql, int qr, int v) {
    updLazy(id, i);
    if (l >= ql && r <= qr) {
        lazy[id][i] += v;
        return tree[id][i] + v;
    }
    if (r < ql || l > qr) return tree[id][i];
    int mid = (l + r) >> 1;
    return tree[id][i] = max(update(id, i << 1, l, mid, ql, qr, v), update(id, i << 1 | 1, mid + 1, r, ql, qr, v));
}

void res(int id, int i) {
    if (tree[id][i] == 0 && lazy[id][i] == 0) return;
    tree[id][i] = lazy[id][i] = 0;
    res(id, i << 1), res(id, i << 1 | 1);
}

int32_t main() {
    boost();

    int t;
    cin >> t;
    while (t--) {
        vector<int> v;
        cin >> n >> k;
        for (int i = 1; i <= n; i++) {
            cin >> x[i];
            segs[i] = {x[i], x[i] + k};
            v.push_back(segs[i].f);
            v.push_back(segs[i].s);
        }
        for (int i = 1; i <= n; i++) cin >> y[i];

        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        sort(segs + 1, segs + n + 1);
        int sz = v.size();
        for (int i = 1; i <= n; i++) {
            segs[i].f = lower_bound(v.begin(), v.end(), segs[i].f) - v.begin() + 1;
            segs[i].s = lower_bound(v.begin(), v.end(), segs[i].s) - v.begin() + 1;
        }
        for (int i = 1; i <= n; i++) update(ALL(1), segs[i].f, segs[i].s, 1);
        int best = query(ALL(1), 1, sz);
        for (int i = 1; i <= n; i++) {
            update(ALL(1), segs[i].f, segs[i].s, -1);
            update(ALL(0), segs[i].f, segs[i].s, 1);
            best = max(best, query(ALL(0), 1, sz) + query(ALL(1), 1, sz));
        }
        printf("%lld\n", best);
        res(0, 1), res(1, 1);
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define readl(_s) getline(cin, (_s));
#define boost() cin.tie(0); cin.sync_with_stdio(0)
#define tree vojpwoekjf
#define ALL(id) id, 1, 1, sz

struct seg {
    int f, s, val;
};

const int MN = 200005;

int n, k, x[MN], y[MN], tree[2][MN * 4], lazy[2][MN * 8];
seg segs[MN];
map<int, int> mp;

bool cmp(seg x, seg y) {
    return x.f < y.f;
}

inline void updLazy(int id, int i) {
    if (lazy[id][i]) {
        tree[id][i] += lazy[id][i];
        lazy[id][i << 1] += lazy[id][i];
        lazy[id][i << 1 | 1] += lazy[id][i];
        lazy[id][i] = 0;
    }
}

int query(int id, int i, int l, int r, int ql, int qr) {
    updLazy(id, i);
    if (l >= ql && r <= qr) return tree[id][i];
    if (r < ql || l > qr) return 0;
    int mid = (l + r) >> 1;
    return max(query(id, i << 1, l, mid, ql, qr), query(id, i << 1 | 1, mid + 1, r, ql, qr));
}

int update(int id, int i, int l, int r, int ql, int qr, int v) {
    updLazy(id, i);
    if (l >= ql && r <= qr) {
        lazy[id][i] += v;
        return tree[id][i] + v;
    }
    if (r < ql || l > qr) return tree[id][i];
    int mid = (l + r) >> 1;
    return tree[id][i] = max(update(id, i << 1, l, mid, ql, qr, v), update(id, i << 1 | 1, mid + 1, r, ql, qr, v));
}

int32_t main() {
    boost();

    int t;
    cin >> t;
    while (t--) {
        vector<int> v;
        cin >> n >> k;
        for (int i = 1; i <= n; i++) {
            cin >> x[i];
            mp[x[i]]++;
        }
        int idx = 1;
        for (pii p : mp) {
            segs[idx] = {p.f, p.f + k, p.s};
            v.push_back(segs[idx].f);
            v.push_back(segs[idx].s);
            idx++;
        }
        for (int i = 1; i <= n; i++) cin >> y[i];

        n = idx - 1;
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        sort(segs + 1, segs + n + 1, cmp);
        int sz = v.size();
        for (int i = 1; i <= n; i++) {
            segs[i].f = lower_bound(v.begin(), v.end(), segs[i].f) - v.begin() + 1;
            segs[i].s = lower_bound(v.begin(), v.end(), segs[i].s) - v.begin() + 1;
            //printf("%d %d %d\n", segs[i].f, segs[i].s, segs[i].val);
        }
        for (int i = 1; i <= n; i++) update(ALL(1), segs[i].f, segs[i].s, segs[i].val);
        int best = query(ALL(1), 1, sz);
        for (int i = 1; i <= n; i++) {
            update(ALL(1), segs[i].f, segs[i].s, -segs[i].val);
            update(ALL(0), segs[i].f, segs[i].s, segs[i].val);
            best = max(best, query(ALL(0), 1, sz) + query(ALL(1), 1, sz));
        }
        printf("%lld\n", best);
        for (int i = 0; i < min(4 * MN, 5000 * sz); i++) tree[0][i] = tree[1][i] = 0;
        for (int i = 0; i < min(8 * MN, 5000 * sz); i++) lazy[0][i] = lazy[1][i] = 0;
        mp.clear();
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define readl(_s) getline(cin, (_s));
#define boost() cin.tie(0); cin.sync_with_stdio(0)
#define tree vojpwoekjf
#define ALL(id) id, 1, 1, sz

struct seg {
    int f, s, val;
};

const int MN = 200005;

int n, k, x[MN], y[MN], tree[2][MN * 16], lazy[2][MN * 16], reset[2][MN * 16];
seg segs[MN];
map<int, int> mp;

bool cmp(seg x, seg y) {
    return x.f < y.f;
}

inline void updLazy(int id, int i) {
    if (lazy[id][i]) {
        tree[id][i] += lazy[id][i];
        lazy[id][i << 1] += lazy[id][i];
        lazy[id][i << 1 | 1] += lazy[id][i];
        lazy[id][i] = 0;
    }
}

int query(int id, int i, int l, int r, int ql, int qr) {
    reset[id][i] = 1;
    updLazy(id, i);
    if (l >= ql && r <= qr) return tree[id][i];
    if (r < ql || l > qr) return 0;
    int mid = (l + r) >> 1;
    return max(query(id, i << 1, l, mid, ql, qr), query(id, i << 1 | 1, mid + 1, r, ql, qr));
}

int update(int id, int i, int l, int r, int ql, int qr, int v) {
    reset[id][i] = 1;
    updLazy(id, i);
    if (l >= ql && r <= qr) {
        lazy[id][i] += v;
        return tree[id][i] + v;
    }
    if (r < ql || l > qr) return tree[id][i];
    int mid = (l + r) >> 1;
    return tree[id][i] = max(update(id, i << 1, l, mid, ql, qr, v), update(id, i << 1 | 1, mid + 1, r, ql, qr, v));
}

void res(int id, int i) {
    if (tree[id][i] == 0 && lazy[id][i] == 0) return;
    reset[id][i] = tree[id][i] = lazy[id][i] = 0;
    res(id, i << 1), res(id, i << 1 | 1);
}

int32_t main() {
    boost();

    int t;
    cin >> t;
    while (t--) {
        vector<int> v;
        cin >> n >> k;
        for (int i = 1; i <= n; i++) {
            cin >> x[i];
            mp[x[i]]++;
        }
        int idx = 1;
        for (pii p : mp) {
            segs[idx] = {p.f, p.f + k, p.s};
            v.push_back(segs[idx].f);
            v.push_back(segs[idx].s);
            idx++;
        }
        for (int i = 1; i <= n; i++) cin >> y[i];

        n = idx - 1;
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        sort(segs + 1, segs + n + 1, cmp);
        int sz = v.size();
        for (int i = 1; i <= n; i++) {
            segs[i].f = lower_bound(v.begin(), v.end(), segs[i].f) - v.begin() + 1;
            segs[i].s = lower_bound(v.begin(), v.end(), segs[i].s) - v.begin() + 1;
            //printf("%d %d %d\n", segs[i].f, segs[i].s, segs[i].val);
        }
        for (int i = 1; i <= n; i++) update(ALL(1), segs[i].f, segs[i].s, segs[i].val);
        int best = query(ALL(1), 1, sz);
        for (int i = 1; i <= n; i++) {
            update(ALL(1), segs[i].f, segs[i].s, -segs[i].val);
            update(ALL(0), segs[i].f, segs[i].s, segs[i].val);
            best = max(best, query(ALL(0), 1, sz) + query(ALL(1), 1, sz));
        }
        printf("%lld\n", best);
        //for (int i = 0; i < min(4 * MN, 3000 * sz); i++) tree[0][i] = tree[1][i] = 0;
        //for (int i = 0; i < min(8 * MN, 3000 * sz); i++) lazy[0][i] = lazy[1][i] = 0;
        mp.clear();
        res(0, 1);
        res(1, 1);
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define readl(_s) getline(cin, (_s));
#define boost() cin.tie(0); cin.sync_with_stdio(0)
#define tree vojpwoekjf
#define ALL(id) id, 1, 1, sz

struct seg {
    int f, s, val;
};

const int MN = 200005;

int n, k, x[MN], y[MN], tree[2][MN * 4], lazy[2][MN * 8], reset[2][MN * 4];
seg segs[MN];
map<int, int> mp;

bool cmp(seg x, seg y) {
    return x.f < y.f;
}

inline void updLazy(int id, int i) {
    if (lazy[id][i]) {
        tree[id][i] += lazy[id][i];
        lazy[id][i << 1] += lazy[id][i];
        lazy[id][i << 1 | 1] += lazy[id][i];
        lazy[id][i] = 0;
    }
}

int query(int id, int i, int l, int r, int ql, int qr) {
    reset[id][i] = 1;
    updLazy(id, i);
    if (l >= ql && r <= qr) return tree[id][i];
    if (r < ql || l > qr) return 0;
    int mid = (l + r) >> 1;
    return max(query(id, i << 1, l, mid, ql, qr), query(id, i << 1 | 1, mid + 1, r, ql, qr));
}

int update(int id, int i, int l, int r, int ql, int qr, int v) {
    reset[id][i] = 1;
    updLazy(id, i);
    if (l >= ql && r <= qr) {
        lazy[id][i] += v;
        return tree[id][i] + v;
    }
    if (r < ql || l > qr) return tree[id][i];
    int mid = (l + r) >> 1;
    return tree[id][i] = max(update(id, i << 1, l, mid, ql, qr, v), update(id, i << 1 | 1, mid + 1, r, ql, qr, v));
}

void res(int id, int i) {
    if (tree[id][i] == 0 && lazy[id][i] == 0) return;
    reset[id][i] = tree[id][i] = lazy[id][i] = 0;
    res(id, i << 1), res(id, i << 1 | 1);
}

int32_t main() {
    boost();

    int t;
    cin >> t;
    while (t--) {
        vector<int> v;
        cin >> n >> k;
        for (int i = 1; i <= n; i++) {
            cin >> x[i];
            mp[x[i]]++;
        }
        int idx = 1;
        for (pii p : mp) {
            segs[idx] = {p.f, p.f + k, p.s};
            v.push_back(segs[idx].f);
            v.push_back(segs[idx].s);
            idx++;
        }
        for (int i = 1; i <= n; i++) cin >> y[i];

        n = idx - 1;
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        sort(segs + 1, segs + n + 1, cmp);
        int sz = v.size();
        for (int i = 1; i <= n; i++) {
            segs[i].f = lower_bound(v.begin(), v.end(), segs[i].f) - v.begin() + 1;
            segs[i].s = lower_bound(v.begin(), v.end(), segs[i].s) - v.begin() + 1;
            //printf("%d %d %d\n", segs[i].f, segs[i].s, segs[i].val);
        }
        for (int i = 1; i <= n; i++) update(ALL(1), segs[i].f, segs[i].s, segs[i].val);
        int best = query(ALL(1), 1, sz);
        for (int i = 1; i <= n; i++) {
            update(ALL(1), segs[i].f, segs[i].s, -segs[i].val);
            update(ALL(0), segs[i].f, segs[i].s, segs[i].val);
            best = max(best, query(ALL(0), 1, sz) + query(ALL(1), 1, sz));
        }
        printf("%lld\n", best);
        //for (int i = 0; i < min(4 * MN, 3000 * sz); i++) tree[0][i] = tree[1][i] = 0;
        //for (int i = 0; i < min(8 * MN, 3000 * sz); i++) lazy[0][i] = lazy[1][i] = 0;
        mp.clear();
        res(0, 1);
        res(1, 1);
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define readl(_s) getline(cin, (_s));
#define boost() cin.tie(0); cin.sync_with_stdio(0)
#define tree vojpwoekjf
#define ALL(id) id, 1, 1, sz

const int MN = 200005;

int n, k, x[MN], y[MN], tree[2][MN * 4], lazy[2][MN * 8], reset[2][MN * 8];
pii segs[MN];

inline void updLazy(int id, int i) {
    if (reset[id][i]) {
        tree[id][i] = lazy[id][i] = 0;
        reset[id][i << 1] = 1;
        reset[id][i << 1 | 1] = 1;
        reset[id][i] = 0;
    }
    if (lazy[id][i]) {
        tree[id][i] += lazy[id][i];
        lazy[id][i << 1] += lazy[id][i];
        lazy[id][i << 1 | 1] += lazy[id][i];
        lazy[id][i] = 0;
    }
}

int query(int id, int i, int l, int r, int ql, int qr) {
    updLazy(id, i);
    if (l >= ql && r <= qr) return tree[id][i];
    if (r < ql || l > qr) return 0;
    int mid = (l + r) >> 1;
    return max(query(id, i << 1, l, mid, ql, qr), query(id, i << 1 | 1, mid + 1, r, ql, qr));
}

int update(int id, int i, int l, int r, int ql, int qr, int v) {
    updLazy(id, i);
    if (l >= ql && r <= qr) {
        lazy[id][i] += v;
        return tree[id][i] + v;
    }
    if (r < ql || l > qr) return tree[id][i];
    int mid = (l + r) >> 1;
    return tree[id][i] = max(update(id, i << 1, l, mid, ql, qr, v), update(id, i << 1 | 1, mid + 1, r, ql, qr, v));
}

int32_t main() {
    boost();

    int t;
    cin >> t;
    while (t--) {
        vector<int> v;
        cin >> n >> k;
        for (int i = 1; i <= n; i++) {
            cin >> x[i];
            segs[i] = {x[i], x[i] + k};
            v.push_back(segs[i].f);
            v.push_back(segs[i].s);
        }
        for (int i = 1; i <= n; i++) cin >> y[i];

        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        sort(segs + 1, segs + n + 1);
        int sz = v.size();
        for (int i = 1; i <= n; i++) {
            segs[i].f = lower_bound(v.begin(), v.end(), segs[i].f) - v.begin() + 1;
            segs[i].s = lower_bound(v.begin(), v.end(), segs[i].s) - v.begin() + 1;
        }
        for (int i = 1; i <= n; i++) update(ALL(1), segs[i].f, segs[i].s, 1);
        int best = query(ALL(1), 1, sz);
        for (int i = 1; i <= n; i++) {
            update(ALL(1), segs[i].f, segs[i].s, -1);
            update(ALL(0), segs[i].f, segs[i].s, 1);
            best = max(best, query(ALL(0), 1, sz) + query(ALL(1), 1, sz));
        }
        printf("%lld\n", best);
        reset[0][1] = reset[1][1] = 1;
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define readl(_s) getline(cin, (_s));
#define boost() cin.tie(0); cin.sync_with_stdio(0)
#define tree vojpwoekjf
#define ALL(id) id, 1, 1, sz

struct seg {
    int f, s, val;
};

const int MN = 200005;

int n, k, x[MN], y[MN], tree[2][MN * 4], lazy[2][MN * 8];
seg segs[MN];
map<int, int> mp;

bool cmp(seg x, seg y) {
    return x.f < y.f;
}

inline void updLazy(int id, int i) {
    if (lazy[id][i]) {
        tree[id][i] += lazy[id][i];
        lazy[id][i << 1] += lazy[id][i];
        lazy[id][i << 1 | 1] += lazy[id][i];
        lazy[id][i] = 0;
    }
}

int query(int id, int i, int l, int r, int ql, int qr) {
    updLazy(id, i);
    if (l >= ql && r <= qr) return tree[id][i];
    if (r < ql || l > qr) return 0;
    int mid = (l + r) >> 1;
    return max(query(id, i << 1, l, mid, ql, qr), query(id, i << 1 | 1, mid + 1, r, ql, qr));
}

int update(int id, int i, int l, int r, int ql, int qr, int v) {
    updLazy(id, i);
    if (l >= ql && r <= qr) {
        lazy[id][i] += v;
        return tree[id][i] + v;
    }
    if (r < ql || l > qr) return tree[id][i];
    int mid = (l + r) >> 1;
    return tree[id][i] = max(update(id, i << 1, l, mid, ql, qr, v), update(id, i << 1 | 1, mid + 1, r, ql, qr, v));
}

int32_t main() {
    boost();

    int t;
    cin >> t;
    while (t--) {
        vector<int> v;
        cin >> n >> k;
        for (int i = 1; i <= n; i++) {
            cin >> x[i];
            mp[x[i]]++;
        }
        int idx = 1;
        for (pii p : mp) {
            segs[idx] = {p.f, p.f + k, p.s};
            v.push_back(segs[idx].f);
            v.push_back(segs[idx].s);
            idx++;
        }
        for (int i = 1; i <= n; i++) cin >> y[i];

        n = idx - 1;
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        sort(segs + 1, segs + n + 1, cmp);
        int sz = v.size();
        for (int i = 1; i <= n; i++) {
            segs[i].f = lower_bound(v.begin(), v.end(), segs[i].f) - v.begin() + 1;
            segs[i].s = lower_bound(v.begin(), v.end(), segs[i].s) - v.begin() + 1;
            //printf("%d %d %d\n", segs[i].f, segs[i].s, segs[i].val);
        }
        for (int i = 1; i <= n; i++) update(ALL(1), segs[i].f, segs[i].s, segs[i].val);
        int best = query(ALL(1), 1, sz);
        for (int i = 1; i <= n; i++) {
            update(ALL(1), segs[i].f, segs[i].s, -segs[i].val);
            update(ALL(0), segs[i].f, segs[i].s, segs[i].val);
            best = max(best, query(ALL(0), 1, sz) + query(ALL(1), 1, sz));
        }
        printf("%lld\n", best);
        for (int i = 0; i < min(4 * MN, 1000 * sz); i++) tree[0][i] = tree[1][i] = 0;
        for (int i = 0; i < min(8 * MN, 1000 * sz); i++) lazy[0][i] = lazy[1][i] = 0;
        mp.clear();
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define readl(_s) getline(cin, (_s));
#define boost() cin.tie(0); cin.sync_with_stdio(0)
#define tree vojpwoekjf
#define ALL(id) id, 1, 1, sz

struct seg {
    int f, s, val;
};

const int MN = 200005;

int n, k, x[MN], y[MN], tree[2][MN * 4], lazy[2][MN * 8];
seg segs[MN];
map<int, int> mp;

bool cmp(seg x, seg y) {
    return x.f < y.f;
}

inline void updLazy(int id, int i) {
    if (lazy[id][i]) {
        tree[id][i] += lazy[id][i];
        lazy[id][i << 1] += lazy[id][i];
        lazy[id][i << 1 | 1] += lazy[id][i];
        lazy[id][i] = 0;
    }
}

int query(int id, int i, int l, int r, int ql, int qr) {
    updLazy(id, i);
    if (l >= ql && r <= qr) return tree[id][i];
    if (r < ql || l > qr) return 0;
    int mid = (l + r) >> 1;
    return max(query(id, i << 1, l, mid, ql, qr), query(id, i << 1 | 1, mid + 1, r, ql, qr));
}

int update(int id, int i, int l, int r, int ql, int qr, int v) {
    updLazy(id, i);
    if (l >= ql && r <= qr) {
        lazy[id][i] += v;
        return tree[id][i] + v;
    }
    if (r < ql || l > qr) return tree[id][i];
    int mid = (l + r) >> 1;
    return tree[id][i] = max(update(id, i << 1, l, mid, ql, qr, v), update(id, i << 1 | 1, mid + 1, r, ql, qr, v));
}

int32_t main() {
    boost();

    int t;
    cin >> t;
    while (t--) {
        vector<int> v;
        cin >> n >> k;
        for (int i = 1; i <= n; i++) {
            cin >> x[i];
            mp[x[i]]++;
        }
        int idx = 1;
        for (pii p : mp) {
            segs[idx] = {p.f, p.f + k, p.s};
            v.push_back(segs[idx].f);
            v.push_back(segs[idx].s);
            idx++;
        }
        for (int i = 1; i <= n; i++) cin >> y[i];

        n = idx - 1;
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        sort(segs + 1, segs + n + 1, cmp);
        int sz = v.size();
        for (int i = 1; i <= n; i++) {
            segs[i].f = lower_bound(v.begin(), v.end(), segs[i].f) - v.begin() + 1;
            segs[i].s = lower_bound(v.begin(), v.end(), segs[i].s) - v.begin() + 1;
            //printf("%d %d %d\n", segs[i].f, segs[i].s, segs[i].val);
        }
        for (int i = 1; i <= n; i++) update(ALL(1), segs[i].f, segs[i].s, segs[i].val);
        int best = query(ALL(1), 1, sz);
        for (int i = 1; i <= n; i++) {
            update(ALL(1), segs[i].f, segs[i].s, -segs[i].val);
            update(ALL(0), segs[i].f, segs[i].s, segs[i].val);
            best = max(best, query(ALL(0), 1, sz) + query(ALL(1), 1, sz));
        }
        printf("%lld\n", best);
        for (int i = 0; i < min(4 * MN, 3000 * sz); i++) tree[0][i] = tree[1][i] = 0;
        for (int i = 0; i < min(8 * MN, 3000 * sz); i++) lazy[0][i] = lazy[1][i] = 0;
        mp.clear();
    }

    return 0;
}