why this code is giving wrong answer?
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1000000000+7;
vector<vector> multiply(int m,vector<vector> &arr,vector<vector> &res){
//creating a temporary 2d array to store the product of two matrices
vector<vector> temp(m,vector(m));
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
temp[i][j]=0;
for(int k=0;k<m;k++){
temp[i][j]=(temp[i][j]+((arr[i][k]*res[k][j])%mod))%mod;
}
}
}
//copying the elements of the temporary matrix to the original matrix
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
arr[i][j]=temp[i][j];
}
}
return temp;
}
void solve(int m,vector<vector> &arr,int n){
//initialising resultant matrix that is initially should be identity matrix
vector<vector> res(m,vector(m,0));
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
if(i==j) res[i][j]=1;
}
}
while(n>0){
if(n%2!=0){
n–;
res=multiply(m,arr,res);
}
n/=2;
arr=multiply(m,arr,arr);
}
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
cout<<res[i][j]<<" ";
}
cout<<endl;
}
}
int main(){
int t;
cin>>t;
while(t–){
int m,n;
cin>>m>>n;
vector<vector> arr(m,vector(m,0));
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
cin>>arr[i][j];
}
}
solve(m,arr,n);
}
}