# THUWC2017 随机二分图

$f[S]$表示集合为$S$的完美匹配期望.

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#define N (15)
#define P (1000000007)
#define inf (0x7f7f7f7f)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
namespace fastIO1{
static const int IN_LEN=1000000;
static char buf[IN_LEN],*s,*t;
}
template<class T>
static bool iosig;
static char c;
if(c=='-')iosig=true;
if(c==-1)return;
}
if(iosig)x=-x;
}
if(c==-1)return 0;
}
const int OUT_LEN = 10000000;
char obuf[OUT_LEN],*ooh=obuf;
inline void print(char c) {
if(ooh==obuf+OUT_LEN)fwrite(obuf,1,OUT_LEN,stdout),ooh=obuf;
*ooh++=c;
}
template<class T>
inline void print(T x){
static int buf[30],cnt;
if(x==0)print('0');
else{
if(x<0)print('-'),x=-x;
for(cnt=0;x;x/=10)buf[++cnt]=x%10+48;
while(cnt)print((char)buf[cnt--]);
}
}
inline void flush(){fwrite(obuf,1,ooh-obuf,stdout);}
}
namespace fastIO2{
template<class T>
static bool iosig;
static char c;
for(iosig=false,c=getchar();!isdigit(c);c=getchar()){
if(c=='-')iosig=true;
if(c==-1)return;
}
for(x=0;isdigit(c);c=getchar())x=((x+(x<<2))<<1)+(c^'0');
if(iosig)x=-x;
}
}
using namespace fastIO1;
const int inv2=(P+1)>>1,inv4=(P+1)>>2;
int n,m,cnt;struct node{LL S;int p;}a[233333];
map<int,int>f[1<<16];
LL calc(int x,int y){return (1ll<<x-1)+(1ll<<(y+n-1));}
int dp(LL S){
if(!S)return 1;
int L=S>>n,R=S^(L<<n);
if(f[L].count(R))return f[L][R];
int ans=0;
for(int i=1;i<=cnt;i++){
LL T=a[i].S;
if((T&S)==T&&(T<<1)>S)
(ans+=1ll*dp(S^T)*a[i].p%P)%=P;
}
return f[L][R]=ans;
}
int main(){
for(int i=1;i<=m;i++){
int tp,x,y;LL S;