why am i getting a runtime error even when the code is working absolutely fine in gdb

```
int t,n,m,counter=0,x;
cin>>t;
for(int a=0;a<t;a++)
{
cin>>n>>m;
int arr[n][m];
x=n*m;
int arr2[x];
counter=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>arr[i][j];
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
arr2[i * m + j] = arr[i][j];
}
}
for(int i=0;i<x;i++)
{
for(int j=i+m;j<x;j=j+m)
{
if((arr2[i]==1)&&(arr2[j]==1))
{
counter=counter+1;
}
}
}
cout<<counter<<endl;
}
return 0;
```

}