#include<iostream>
using namespace std;
const int N = 1e5+10;
const int M = 1e6+10;
int n,m;
int ne[N];
char p[N],s[M];
int main()
{
cin>>n>>p+1>>m>>s+1;
int i,j;
ne[1] = 0;
i = 1,j = 0;
while(i<=n){
if(j==0||p[i]==p[j])
{
i++,j++;
ne[i] = j;
}
else j = ne[j];
}
i = 1,j = 1;
while(i<=m){
if(j==0||s[i]==p[j])
{
i++,j++;
if (j > n) {
cout<<i - n - 1<<" ";
j = ne[j]; // 继续查找下一个匹配
}
}
else j = ne[j];
}
}