Help me in solving TRISWP problem

My issue

#include<bits/stdc++.h>

using namespace std;

int main() {
int t; cin >> t;
while (t–) {
int n; cin >> n;
string s1; cin >> s1;
unordered_set ss;
for (int i = 0; i <= n - 3; ++i)
{
swap(s1[i], s1[i + 2]);
swap(s1[i], s1[i + 1]);
ss.insert(s1);
swap(s1[i], s1[i + 1]);
swap(s1[i], s1[i + 2]);
}
if(ss.empty()){
cout<<0<<endl;
continue;
}
cout << (int)ss.size() << endl;

}

}

why is this giving runtime error can anyone explain

My code

#include<bits/stdc++.h>

using namespace std;

int main() {
    int t; cin >> t;
    while (t--) {
        int n; cin >> n;
        string s1; cin >> s1;
        unordered_set<string> ss;
        for (int i = 0; i <= n - 3; ++i)
        {
            swap(s1[i], s1[i + 2]);
            swap(s1[i], s1[i + 1]);
            ss.insert(s1);
            swap(s1[i], s1[i + 1]);
            swap(s1[i], s1[i + 2]);
        }
        if(ss.empty()){
            cout<<0<<endl;
            continue;
        }
        cout << (int)ss.size() << endl;


    }
}

Problem Link: Triangular Swaps Practice Coding Problem - CodeChef