#include using namespace std; using ll = long long; using pll = pair; #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); const ll MOD1000000007 = 1000000007; const ll MOD998244353 = 998244353; const ll MOD[3] = {999727999, 1070777777, 1000000007}; const ll LINF = 1LL << 60LL; const int IINF = (1 << 30) - 1; template class modint{ long long x; public: modint(long long x=0) : x((x%mod+mod)%mod) {} modint operator-() const { return modint(-x); } bool operator==(const modint& a){ if(x == a) return true; else return false; } bool operator==(long long a){ if(x == a) return true; else return false; } bool operator!=(const modint& a){ if(x != a) return true; else return false; } bool operator!=(long long a){ if(x != a) return true; else return false; } modint& operator+=(const modint& a) { if ((x += a.x) >= mod) x -= mod; return *this; } modint& operator-=(const modint& a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } modint& operator*=(const modint& a) { (x *= a.x) %= mod; return *this; } modint operator+(const modint& a) const { modint res(*this); return res+=a; } modint operator-(const modint& a) const { modint res(*this); return res-=a; } modint operator*(const modint& a) const { modint res(*this); return res*=a; } modint pow(long long t) const { if (!t) return 1; modint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod modint inv() const { return pow(mod-2); } modint& operator/=(const modint& a) { return (*this) *= a.inv(); } modint operator/(const modint& a) const { modint res(*this); return res/=a; } friend std::istream& operator>>(std::istream& is, modint& m) noexcept { is >> m.x; m.x %= mod; if (m.x < 0) m.x += mod; return is; } friend ostream& operator<<(ostream& os, const modint& m){ os << m.x; return os; } }; template struct matrix{ vector> A; matrix(){} matrix(size_t n, size_t m) : A(n, vector(m, 0)){} matrix(size_t n) : A(n, vector(n, 0)){}; size_t height() const{return (A.size());} size_t width() const{return (A[0].size());} inline const vector &operator[](int k) const{return (A.at(k));} inline vector &operator[](int k){return (A.at(k));} static matrix I(size_t n){ matrix mat(n); for(int i=0; i> C(n, vector(m, 0)); for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) for(int k = 0; k < p; k++) C[i][j] = (C[i][j] + (*this)[i][k] * B[k][j]); A.swap(C); return (*this); } matrix &operator^=(long long k){ matrix B = matrix::I(height()); while(k > 0) { if(k & 1) B *= *this; *this *= *this; k >>= 1LL; } A.swap(B.A); return (*this); } matrix operator+(const matrix &B) const{ return (matrix(*this) += B); } matrix operator-(const matrix &B) const{ return (matrix(*this) -= B); } matrix operator*(const matrix &B) const{ return (matrix(*this) *= B); } matrix operator^(const long long k) const{ return (matrix(*this) ^= k); } friend ostream &operator<<(ostream &os, matrix &p){ size_t n = p.height(), m = p.width(); for(int i=0; i; template T count_spanning_tree(vector> &G){ int n = (int)G.size(); if(n==1) return T(1); matrix L(n); for(int v=0; v L11(n-1); for(int i=0; i> k; vector cnt1(k, 0), cnt2(k, 0); for(int i=0; i> n >> m; vector> G1(n), G2(n-1); for(int i=0; i> u >> v; u--; v--; G1[u].push_back(v); G1[v].push_back(u); } for(int v=0; v(G1); cnt2[i] = count_spanning_tree(G2); } for(int i=0; i> G(2*k+2); int x = 2*k, y = 2*k+1; for(int i=0; i> T; while(T--) solve(); }