#include#include #include using namespace std;int mp[30][250][250];int main(){ int n,u,v,i,j,l,k,p,f; char s[1024]; while(~scanf("%d",&n)) { if(n==0) break; memset(mp,0,sizeof(mp)); while(~scanf("%d%d",&u,&v)) { if(u==0&&v==0) break; scanf("%s",s); l=strlen(s); for(j=0; j