#include using namespace atcoder; #include using namespace internal; #include using namespace std; #include #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i,a,b) for (int i = (int)(a); i < (int)(b); i++) #define all(v) v.begin(),v.end() #define inc(x,l,r) ((l)<=(x)&&(x)<(r)) #define Unique(x) sort(all(x)), x.erase(unique(all(x)), x.end()) #define pcnt __builtin_popcountll typedef long long ll; #define int ll using ld = long double; using vi = vector; using vs = vector; using P = pair; using vp = vector

; using Bint = boost::multiprecision::cpp_int; template bool chmax(T1 &a, const T2 b) {if (a < b) {a = b; return true;} else return false; } template bool chmin(T1 &a, const T2 b) {if (a > b) {a = b; return true;} else return false; } template using priority_queue_greater = priority_queue, greater>; template ostream &operator<< (ostream &os, const pair &p){os << p.first <<" "<> (istream &is, modint1000000007 &m){ll in;is>>in;m=in;return is;} ostream &operator<< (ostream &os, const modint998244353 &m){os << m.val();return os;} istream &operator>> (istream &is, modint998244353 &m){ll in;is>>in;m=in;return is;} template istream &operator>>(istream& is,vector &v){for(T &in:v)is>>in;return is;} template void input(T&... a){(cin>> ... >> a);} #ifdef LOCAL template ostream &operator<<(ostream &os,const vector &v){os<<"\x1b[32m";rep(i,v.size())os< int print(T& a){cout << "\x1b[32m"<< a<< '\n' << "\x1b[0m";return 0;} template int print(const T&a, const Ts&... b){cout << "\x1b[32m" << a;(cout<<...<<(cout<<' ',b));cout<<'\n' << "\x1b[0m";return 0;} #else template ostream &operator<<(ostream &os,const vector &v){rep(i,v.size())os< int print(T& a){cout << a<< '\n';return 0;} template int print(const T&a, const Ts&... b){cout << a;(cout<<...<<(cout<<' ',b));cout<<'\n';return 0;} #endif #define VI(v,n) vi v(n); input(v) #define INT(...) int __VA_ARGS__; input(__VA_ARGS__) #define STR(...) string __VA_ARGS__; input(__VA_ARGS__) #define CHAR(...) char __VA_ARGS__; input(__VA_ARGS__) int sign(ll x){return x>0?1:x<0?-1:0;} ll ceil(ll x,ll y){assert(y!=0);if(sign(x)==sign(y))return (x+y-1)/y;return -((-x/y));} ll floor(ll x,ll y){assert(y!=0);if(sign(x)==sign(y))return x/y;if(y<0)x*=-1,y*=-1;return x/y-(x%y<0);} ll abs(ll x,ll y){return abs(x-y);} ll bit(int n){return 1ll< bool ins(string s,T t){return s.find(t)!=string::npos;} P operator+ (const P &p, const P &q){ return P{p.first+q.first,p.second+q.second};} P operator- (const P &p, const P &q){ return P{p.first-q.first,p.second-q.second};} int yesno(bool ok,string y="Yes",string n="No"){ cout<<(ok?y:n)<(chrono::system_clock::now().time_since_epoch()).count() % mod; template struct RollingHash { vector hash, hash_rev, base_pow; string S; string Srev; static constexpr ull mask(ll a){ return (1ULL << a) - 1; } inline ull mul(ull a, ull b) const { __uint128_t ans = __uint128_t(a) * b; ans = (ans >> 61) + (ans & mod); if(ans >= mod) ans -= mod; return ans; } RollingHash(const string &s):S(s) { int n = s.size(); if(use_reverse){ Srev = s; reverse(Srev.begin(),Srev.end()); hash_rev.assign(n + 1, 0); } hash.assign(n + 1, 0); base_pow.assign(n + 1, 0); base_pow[0] = 1; for(int i = 0; i < n; i++) { base_pow[i + 1] = mul(base_pow[i], base); hash[i + 1] = mul(hash[i], base) + s[i]; if(hash[i + 1] >= mod) hash[i + 1] -= mod; } if(use_reverse){ for(int i = 0; i < n; i++) { hash_rev[i + 1] = mul(hash_rev[i], base) + Srev[i]; if(hash_rev[i + 1] >= mod) hash_rev[i + 1] -= mod; } } } ull between(int l, int r, bool rev = false) const { ull ret; if(rev){ assert(use_reverse); ret = hash_rev[hash_rev.size() - l - 1] + mod - mul(hash_rev[hash_rev.size() - r - 1], base_pow[r - l]); } else ret = hash[r] + mod - mul(hash[l], base_pow[r - l]); if(ret >= mod) ret -= mod; return ret; } ull connect(ull h1, ull h2, int h2len) const { ull ret = mul(h1, base_pow[h2len]) + h2; if(ret >= mod) ret -= mod; return ret; } void connect(const string &s){ int n = hash.size() - 1, m = s.size(); hash.resize(n + m + 1); base_pow.resize(n + m + 1); for(int i = n; i < n + m; i++) { base_pow[i + 1] = mul(base_pow[i], base); hash[i + 1] = mul(hash[i], base) + s[i - n]; if(hash[i + 1] >= mod) hash[i + 1] -= mod; } } bool ispalindrome(int l,int r){ return between(l,r) == between(l,r,true); } int lcp(const RollingHash &b, int l1, int r1, int l2, int r2) { if(S[l1]!=b.S[l2])return 0; int len = min(r1 - l1, r2 - l2); int low = -1, high = len + 1; while(high - low > 1) { int mid = (low + high) / 2; if(between(l1, l1 + mid) == b.between(l2, l2 + mid)) low = mid; else high = mid; } return low; } //[l1,r1) < b.[l2,r2] return -1 // = 0 // > 1 int comp(const RollingHash &b,int l1,int r1,int l2,int r2){ int len = lcp(b,l1,r1,l2,r2); if(len == r1-l1){ if(len == r2-l2)return 0; return -1; } if(len == r2-l2)return 1; return (S[l1+len] < b.S[l2+len]?-1:1); } }; signed main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); INT(t); while(t--){ INT(n); STR(s); RollingHash r(s); int res = 0; for(int i=1;i