SIGSEV error

Here is my code,when running on gcc compiler and online compiler link text it is working fine. When running on codechef it is showing SIGSEV ,please tell me error in the code. The question is link text.

CODE:

#include<bits/stdc++.h>
#include<vector>
#include<string>
using namespace std;
int main()
{
 int T;
 cin>>T;
 while(T--){
  int N,M,count=0;
  cin>>N>>M;
  string arr[N];
  for(int i =0;i<N;i++){
   cin>>arr[i];
  }
  
  for(int i =0;i<N;i++){
   char ch = arr[i][0];
   
   for(int j=1;j<M;j++){
    //cout<<ch<<endl;
    if( (ch == 'R') && (arr[i][j] == 'R')){
     


     int k = i+1;
     while(arr[i][k] != 'G')
     k++;
     char te = arr[i][j];
     arr[i][j] = arr[i][k];
     arr[i][k] = te;
     count += 5;
     ch = arr[i][j];
    }else if((ch == 'G') && (arr[i][j] == 'G')){
	  
	  int k = i+1;
     while(arr[i][k] != 'R')
     k++;
     char te = arr[i][j];
     arr[i][j] = arr[i][k];
     arr[i][k] = te;

      count += 3;
      ch = arr[i][j];
    }else{
     ch = arr[i][j];
    }
    
   }
  
  }
  
  cout << count<<endl;
 } 
}