#include<algorithm>
#include<iostream>
#include<cmath>
#include<queue>
#include<map>
#include<vector>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
const int maxn=5e2+34;
//int a[505];
//map<ll,ll> vis;
char s[maxn];
ll MOD=1e9+7;
ll read(){
ll flag=1,res=0;
char ch=getchar();
while(!isdigit(ch)){
if(ch=='-')flag=-1;
ch=getchar();
}
while(isdigit(ch)){
res=res*10+ch-'0';
ch=getchar();
}
return res*flag;
}
ll quick_pow(ll x,ll y){
ll res=1;
while(y){
if(y&1)res=res*x%MOD;
x=x*x%MOD;
y>>=1;
}
return res;
}
void work(){
ll n,m,x,y;
ll v=0,z;
n=read(),m=read();
for(int i=1;i<=m;i++){
read(),read();
v|=read();
v%=MOD;
}
v*=quick_pow(2ll,n-1);
v%=MOD;
printf("%lld\n",v);
}
int main()
{
int t=1;
scanf("%d",&t);
while(t--)
work();
return 0;
}``