Help me in solving TRISWP problem

My issue

This is my code could anyone pls tell me why this gives run time error even all endcases are taken care of pls suggest the endcase which results in run time error.

My code

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

int main()
{
  int t;
  cin >> t;
  while (t--)
  {
    int n;
    cin >> n;
    string s;
    cin >> s;
    unordered_set<string> st;
    for (int i = 0; i <= n - 3; i++)
    {
      string tmp = s;
      swap(tmp[i], tmp[i + 1]);
      swap(tmp[i + 1], tmp[i + 2]);
      st.insert(tmp);
    }
    cout<<st.size()<<endl;
  }
  return 0;
}

Problem Link: Triangular Swaps Practice Coding Problem - CodeChef