#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define fi first #define se second #define mp make_pair #define mt make_tuple #define pqueue priority_queue const int inf=1e9+7; const ll mod=1e9+7; const ll mod1=998244353; const ll big=1e18; const double PI=2*asin(1); ll mypow(ll a, ll b) { ll ans = 1; ll two; ll tmp; while(b>0) { two = 1; tmp = a; while(2*two>S; ll ans[S]; ll N, M, X; for(int i=0;i>N>>M>>X; if(X==1) ans[i] = (mypow(1+M, N)-mypow(1-M+mod, N)+mod)%mod*mypow(2, mod-2)%mod; else ans[i] = (mypow(1+M, N)+mypow(1-M+mod, N))%mod*mypow(2, mod-2)%mod; } for(int i=0;i