#include #include #include #include #include #include #include #include #include #define infile(filename) freopen(filename".in","r",stdin) #define outfile(filename) freopen(filename".out","w",stdout) #define usefile(filename) infile(filename),outfile(filename) using namespace std; typedef long long ll; typedef unsigned long long ull; char gc() { static const int BUF=1<<20; static char ch[BUF],*l=ch,*r=ch; return (l==r&&(r=(l=ch)+fread(ch,1,BUF,stdin),l==r))?EOF:*l++; } template void read(T &a) { static char ch,fushu; fushu=a=0; do ch=gc(); while(ch!='-'&&(ch<48||ch>57)); if(ch=='-') fushu=1,ch=gc(); do a=(a<<1)+(a<<3)+(ch^48),ch=gc(); while(ch>47&&ch<58); if(fushu) a=-a; return ; } template void read(T &a,Args &...args) { read(a),read(args...); } const int N=100099,moder=1000000007; int add(int x,int y) { return x+y>=moder?x+y-moder:x+y; } int Add(int &x,int y) { return x=x+y>=moder?x+y-moder:x+y; } int sub(int x,int y) { return x>=1) { if(b&1) rey=rey*temp%moder; temp=temp*temp%moder; } return rey; } int T,n,m,v; pair a[N]={}; int main() { usefile("assign"); int i,ans; auto calc=[&](int cnt)->int { return sub(kuai(v,2*cnt),(ll)kuai(v,cnt-1)*(v-1)%moder); }; read(T); loop : --T; read(n,m,v); for(i=1;i<=m;++i) read(a[i].first,a[i].second); sort(a+1,a+1+m); for(i=ans=1;i