struct Matrix {
int r, c;
LL m[MAXN][MAXN];
Matrix(){}
Matrix(int r, int c) : r(r), c(c){};
void clear() {
memset(m, 0, sizeof(m));
}
void init() {
for (int i = 1; i <= r; i++) m[i][i] = 1;
}
Matrix operator * (const Matrix B) const {
Matrix C(r, B.c);
for (int i = 1; i <= C.r; i++) {
for (int j = 1; j <= C.c; j++) {
C.m[i][j] = 0;
for (int k = 1; k <= c; k++) {
C.m[i][j] += ((m[i][k] * B.m[k][j]) % mod) % mod;
}
}
}
return C;
}
Matrix operator ^ (const int p) const {
int t = p;
Matrix res(r, r), tmp(r, r);
res.clear();
for (int i = 1; i <= r; i++) res.m[i][i] = 1;
memcpy(tmp.m, m, sizeof(tmp.m));
while (t) {
if (t & 1) res = res * tmp;
tmp = tmp * tmp;
t >>= 1;
}
return res;
}
}