#define Plus_Cat "assign" #include #define INF 0x3f3f3f3f #define ll long long #define RCL(a,b,c,d) memset(a,b,sizeof(c)*(d)) #define tomin(a,...) ((a)=min({(a),__VA_ARGS__})) #define tomax(a,...) ((a)=max({(a),__VA_ARGS__})) #define FOR(i,a,b) for(int i(a); i<=(int)(b); ++i) #define DOR(i,a,b) for(int i(a); i>=(int)(b); --i) #define EDGE(g,i,x,y) for(int i(g.h[x]),y(g[i].v); ~i; y=g[i=g[i].nxt].v) using namespace std; constexpr int N(1e9+10),M(1e5+10); namespace IOEcat { #define isD(c) ('0'<=(c)&&(c)<='9') #define DE(...) E(#__VA_ARGS__,__VA_ARGS__) struct Icat { char getc() { return getchar(); } templatevoid operator ()(T &x) { static bool sign(0); static char ch(0); sign=0,x=0; while(ch=getc(),!isD(ch))if(ch=='-')sign=1; do x=(x<<1)+(x<<3)+(ch^48); while(ch=getc(),isD(ch)); if(sign)x=-x; } templatevoid operator ()(T &x,Types&...args) { return (*this)(x),(*this)(args...); } } I; struct Ocat { void putc(char c) { putchar(c); } templatevoid operator ()(T x,const char lst='\n') { static int top(0); static char st[50]; if(x<0)x=-x,putc('-'); do st[++top]=(x%10)^48,x/=10; while(x); while(top)putc(st[top--]); putc(lst); } templatevoid operator ()(T x,const char lst='\n',Types...args) { return (*this)(x,lst),(*this)(args...); } } O; struct Ecat { templatevoid operator ()(const char *fmt,const T x) { cerr<void operator ()(const char *fmt,const T x,const Types...args) { while(*fmt^',')cerr<<*fmt++; return cerr<<':'<constexpr auto add(T1 a,T2 b) { return a+b>=Mod?a+b-Mod:a+b; } templateT1 &toadd(T1 &a,T2 b) { return a=add(a,b); } templateconstexpr auto mul(T1 a,T2 b) { return (ll)a*b%Mod; } templateT1 &tomul(T1 &a,T2 b) { return a=mul(a,b); } int Pow(int a,int b=Mod-2) { int res(1); for(a%=Mod; b; b>>=1,tomul(a,a))if(b&1)tomul(res,a); return res; } } using namespace Modular; int Cas,n,m,v,ans; struct node { int c,d; friend bool operator <(node a,node b) { return a.c1)tomul(ans,Pow(v,2*(a[1].c-1))); FOR(i,1,m-1)if(a[i].c!=a[i+1].c) { int val(add( Pow(v,2*(a[i+1].c-a[i].c)), Mod-mul(v-1,Pow(v,a[i+1].c-a[i].c-1)) )); tomul(ans,val); } if(a[m].c