I,R=input,range N=int(I()) T=I() P=998244353 Q=10**9+7 p=[1] for n in R(11**5):p+=[p[-1]*P%Q] p[-1]=pow(P,-1,Q) def C(U,V): return [(U[0]+V[0]*U[1])%Q,U[1]*V[1]%Q,U[2],(U[3]+sum(U[2][i]*V[4][L-2-i] for i in R(L-1))+V[3])%P,V[4]] L=len(T) u=v=0 A=[0]*L B=[0]*L for i in R(L): A[i]=u=(u+ord(T[i])*p[i])%Q B[i]=v=(ord(T[L-1-i])+v*P)%Q S=[0]*N for n in R(N): s=I().split() u=v=m=0 c,U,V=s[0],[0]*L,[0]*L l=len(c) for i in R(l): t,v=ord(c[i]),(ord(c[l-1-i])+v*P)%Q u=(u+t*p[i])%Q if i