#include using namespace std; const int64_t MOD = 1e9+7; void add(int64_t& a, int64_t b){ a = (a+b) % MOD; } void mul(int64_t& a, int64_t b){ a = a*b % MOD; } typedef vector> Mat; Mat matmul(Mat A, Mat B){ assert(A[0].size() == B.size()); int N = A.size(), M = B[0].size(), K = B.size(); Mat ans(N, vector(M)); for(int i=0; i> K >> M >> N; auto encode = [&](int i, int j){ return i*K+j; }; vector P(M), Q(M), R(M); for(int i=0; i> P[i] >> Q[i] >> R[i]; P[i]--; Q[i]--; R[i]--; } int S = K*K; Mat X(S, vector(S)), A(S, vector(1)); for(int i=0; i