#include #include using namespace std; int main() { int t; cin >> t; while (t--) { int n; string s; cin >> n >> s; vector z = atcoder::z_algorithm(s); int ans = 0; for (int i = 1; i < n; i++) { if (i < z[i]) ans++; else if (i == z[i]) { if (2 * i < n) ans++; } else { int k = z[i]; if (i + k < n && s[k] < s[i + k]) ans++; } } cout << ans << '\n'; } }