/***************************************************************** Author:lbn187, a konjac TwT Date:2016-03-05 Contest:Bestcoder Algorithm:QAQ ^_^ Orz hzh, NOI gold members, IOI 2016 world champion ^=^ Orz hhw, you are our blue moon, with you will live ^~^ Orz mxh, you are our red sun, without you we'll die ^-^ Orz yizhou, I wish you a successful marriage ^w^ Orz xianyangyu, you can sleep all the time in the game *****************************************************************/ #pragma comment(linker, "/STACK:1024000000,1024000000") #include #include #include #include #include #include #include #include #define fo(i,n) for(int i=0;i=0;i--) #define rep(i,a,n) for(int i=a;i<=n;i++) #define per(i,a,n) for(int i=n;i>=a;i--) #define mjj(i,x) for(int i=fir[x];i;i=ne[i]) #define X first #define Y second #define MAX(a,b) a=max(a,b) #define MIN(a,b) a=min(a,b) #define mp make_pair #define gi(a) scanf("%d",&a); #define gi2(a,b) scanf("%d%d",&a,&b); #define gi3(a,b,c) scanf("%d%d%d",&a,&b,&c); #define gl(a) scanf("%I64d",&a); #define gs(s) scanf("%s",s); #define wi(a) printf("%d\n",a); #define wi2(a,b) printf("%d %d\n",a,b); #define wl(a) printf("%I64d\n",a); #define spr(x) (x*x) #define pi acos(-1) #define CM(a,b) memcpy(a,b,sizeof(b)) #define CL(a) memset(a,0,sizeof(a)) #define N 133333 #define W 12345678 #define M 1000000007 #define inf 1e9 #define eps 1e-8 using namespace std; typedef long long LL;typedef unsigned long long ULL;typedef double LF;typedef long double LD; typedef pairpii;typedef pairpil;typedef pairpli;typedef pairpll;typedef pairpff; const int xx[]={1,-1,0,0},yy[]={0,0,1,-1};LL pow(LL a,LL b,LL p){LL sum=1;for(a%=p;b;a=a*a%p,b>>=1)if(b&1)sum=sum*a%p;return sum;} char ch;void rd(int &x){for(ch=getchar();ch<'0';ch=getchar());for(x=0;ch>='0';ch=getchar())x=x*10+ch-'0';} LL phi(LL n){LL i,re=n;for(i=2;i*i<=n;i++)if(n%i==0){re=re/i*(i-1);while(n%i==0)n/=i;}if(n>1)re=re/n*(n-1);return re%M;} void exgcd(LL a,LL b,LL &x,LL &y){if(!b){x=1;y=0;return;}exgcd(b,a%b,y,x);y-=x*(a/b);} LL gcd(LL a,LL b){return b==0?a:gcd(b,a%b);} int T,n,m,x,y,i,j,h,t,tot,a[N],d[N],q[N];//la[W],ne[W],fir[W]; int main(){ scanf("%d",&T); for(;T--;){ LL S=0; scanf("%d%d",&n,&m);memset(d,63,sizeof(d)); for(i=1;i<=n;i++)scanf("%d",&a[i]); for(h=0,q[t=1]=0,d[0]=0;h^t;){ x=q[++h]; for(i=0;i<=16;i++){ y=x^(1<1e7){ d[y]=d[x]+1;q[++t]=y; } } for(i=1;i<=n;i++){ y=x^a[i]; if(d[y]>1e7){ d[y]=d[x]+1;q[++t]=y; } } } for(i=1;i<=m;i++){ scanf("%d%d",&x,&y); S=(S+1ll*i*d[x^y])%M; } printf("%lld\n",S); //fr(i,n)scanf("%d",&a[i]); } }