裸题
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<queue>
#include<map>
#include<cmath>
#include<stack>
#include<set>
#include<vector>
#include<algorithm>
#define ll long long
#define inf 1<<30
using namespace std;
int MAXN;
int mod;
struct Matrix
{
ll mat[15][15];
Matrix() {}
Matrix operator*(Matrix const &b)const
{
Matrix res;
memset(res.mat, 0, sizeof(res.mat));
for (int i = 1 ;i <=MAXN; i++)
for (int j = 1; j <= MAXN; j++)
for (int k = 1; k <=MAXN; k++)
res.mat[i][j] = (res.mat[i][j]+this->mat[i][k] * b.mat[k][j])%mod;
return res;
}
};
Matrix pow_mod(Matrix base, int n)
{
Matrix res;
memset(res.mat, 0, sizeof(res.mat));
for (int i = 1; i <=MAXN; i++)
res.mat[i][i] = 1;
while (n > 0)
{
if (n & 1) res = res*base;
base = base*base;
n >>= 1;
}
return res;
}
int s[150];
int main()
{
int n,k,m,t;
Matrix base,a;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
mod=9973;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
scanf("%lld",&base.mat[i][j]);
MAXN=n;
Matrix ans=pow_mod(base,m);
ll sum=0;
for(int i=1;i<=n;i++)
{
//printf("!%lld\n",base.mat[i][i]);
sum=(sum+ans.mat[i][i])%mod;
}
printf("%lld\n",sum);
}
}