Help me in solving TRISWP problem

My issue

why is this code giving the runtime error even though i am considering all the constraints, and the only for loop is within the constraint given in the question.

My code

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t; 
	cin >> t;
	while(t--)
	{
	    int n; 
	    cin >> n;
	    string s;
	    cin >>s;
	    string k = s;
	    map<string,int> arr;
	    int count = 0;
	    arr[k]=0;
	   // count++;
	    char temp;
	    for(int i=0; i<n-2; i++)
	    {
	        k = s;
	        temp = k[i];
	        k[i] = k[i+1];
	        k[i+1] = k[i+2];
	        k[i+2] = temp;
	        if(arr[k] == 0)
	        {
	            arr[k]++;
	            count++;
	        }
	    }
	    cout << count << endl;
	    
	}
	

}

Problem Link: Triangular Swaps Practice Coding Problem - CodeChef