#include using namespace std; #if __has_include() #include using namespace atcoder; #endif using ll = long long; using ld = long double; #define all(s) (s).begin(),(s).end() #define rep2(i, m, n) for (int i = (m); i < (n); ++i) #define rep(i, n) rep2(i, 0, n) #define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i) #define drep(i, n) drep2(i, n, 0) #define rever(vec) reverse(vec.begin(), vec.end()) #define sor(vec) sort(vec.begin(), vec.end()) #define fi first #define se second #define P pair const ll mod = 998244353; //const ll mod = 1000000007; const ll inf = 2000000000000000000ll; static const long double pi = 3.141592653589793; void vcin(vector &n){for(int i=0;i>n[i];} void vcout(vector &n){for(int i=0;i void chmax(T& t,const U& u){if(t void chmin(T& t,const U& u){if(t>u) t=u;} ll modPow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; } using mint = modint998244353; using fps = vector; vector graph[100100]; bool seen[100100],finish[100100],roop[100100]; ll a[100100],c[100100]; fps g; ll pos=-1,n,k,U,V,csize=0; stack s; map m; map cyclecount; mint ans; mint anscycle; mint ansno; map mf; fps onediv(mint c) { int n = g.size(); fps r=g; for(int i=0;i>n>>k; ll u=k; assert(3<=n&&n<=100000&&2<=k&&k<=6); k=modPow(1-k+mod,mod-2,mod); for(int i=0;i>x>>y; x--; y--; assert(0<=x&&x> f; //g(i)を求める for(int i=0;i fp(2); fp[0]=1; fp[1]=modPow(k,c[i],mod)-1; f.push(fp); } } while(f.size()>1){ auto p=f.front(); f.pop(); auto q=f.front(); f.pop(); p=convolution(p,q); f.push(p); } auto s=f.front(); for(int i=0;i check; for(int i=0;i