
#include<map>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define PII pair<int, int>
#define PSS pair<string, string>
#define VINT vector<int>
#define fi first
#define se second
#define mkp make_pair
#define Pque priority_queue
#define pb push_back
using namespace std;
typedef long long LL;
const int maxn = 1e5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int n, m, tot;
char ss[maxn + 5];
bool vis[maxn + 5];
int fail[maxn + 5], trie[maxn + 5][130];
int bianhao[maxn + 5];//当前结束位置的病毒编号
void getfail(){
queue<int> q;
for(int i = 0; i <= 128; i++){
if(trie[0][i]){
fail[trie[0][i]] = 0;
q.push(trie[0][i]);
}
}
while(!q.empty()){
int now = q.front(); q.pop();
for(int i = 0; i <= 128; i++){
if(trie[now][i]){
fail[trie[now][i]] = trie[fail[now]][i];
q.push(trie[now][i]);
}
else trie[now][i] = trie[fail[now]][i];
}
}
return;
}
int main(){
scanf("%d",