#include #include using namespace std; void solve() { int N; cin >> N; string S; cin >> S; vector sa = atcoder::suffix_array(S); vector z = atcoder::z_algorithm(S); int ans = 0; for(int i = 0; i < N; i++) { if(sa[i] == 0) { ans += N - 1 - i; break; } int u = z[sa[i]]; if(u + sa[i] == N) { if(u < (N + 1) / 2) { ans++; } } } cout << ans << '\n'; } int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); int T; cin >> T; while(T--) { solve(); } return 0; }