#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;

#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const int  N     =  2e5+5;
const int  mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const int  LEVEL =  log2(N)+1;

ll n, cnt[N];

vector <int> LPS(string s) {
    int n = s.length();
    vector <int> lps(n, 0);
    for (int i = 1; i < n; i++) {
        int j = lps[i-1];
        while(j > 0 && s[i] != s[j]) j = lps[j-1];
        if(s[i] == s[j]) j++;
        lps[i] = j;
        cnt[j]++;
    }
    return lps;
}

void solve(){
	string s;
	cin >> s;
	vector <int> lps = LPS(s);
	int j = lps[s.size() - 1];
	vpll ans;
	ans.pb({s.size(), 1});
	int prv = 0;
	while(j){
		ans.pb({j, cnt[j] + prv + 1});
		prv += cnt[j];
		j = lps[j - 1];
	}
	reverse(all(ans));
	deb1(ans.size())
	for(auto it : ans) deb2(it.f, it.s)
}

int main(){
	GODSPEED;
	int test = 1;
	//cin >> test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}


#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;

#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const int  N     =  2e5+5;
const int  mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const int  LEVEL =  log2(N)+1;

ll n, cnt[N];

vector <int> LPS(string s) {
    int n = s.length();
    vector <int> lps(n, 0);
    for (int i = 1; i < n; i++) {
        int j = lps[i-1];
        while(j > 0 && s[i] != s[j]) j = lps[j-1];
        if(s[i] == s[j]) j++;
        lps[i] = j;
        cnt[j]++;
    }
    return lps;
}

void solve(){
	string s;
	cin >> s;
	vector <int> lps = LPS(s);
	int j = lps[s.size() - 1];
	vpll ans;
	ans.pb({s.size(), 1});
	int prv = 0;
	while(j){
		ans.pb({j, cnt[j] + prv + 1});
		prv = cnt[j];
		j = lps[j - 1];
	}
	reverse(all(ans));
	deb1(ans.size())
	for(auto it : ans) deb2(it.f, it.s)
}

int main(){
	GODSPEED;
	int test = 1;
	//cin >> test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}


#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;

#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const int  N     =  2e5+5;
const int  mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const int  LEVEL =  log2(N)+1;

ll n, cnt[N], suf[N];

vector <int> LPS(string s) {
    int n = s.length();
    vector <int> lps(n, 0);
    for (int i = 1; i < n; i++) {
        int j = lps[i-1];
        while(j > 0 && s[i] != s[j]) j = lps[j-1];
        if(s[i] == s[j]) j++;
        lps[i] = j;
        cnt[j]++;
    }
    return lps;
}

void solve(){
	string s;
	cin >> s;
	vector <int> lps = LPS(s);
	int j = lps[s.size() - 1];
	vpll ans;
	ans.pb({s.size(), 1});
	for(int i = s.size() - 1; i > 0; i--){
		cnt[lps[i - 1]] += cnt[i];
	}
	while(j){
		ans.pb({j, cnt[j] + 1});
		j = lps[j - 1];
	}
	reverse(all(ans));
	deb1(ans.size())
	for(auto it : ans) deb2(it.f, it.s)
}

int main(){
	GODSPEED;
	int test = 1;
	//cin >> test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}


#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;

#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const int  N     =  2e5+5;
const int  mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const int  LEVEL =  log2(N)+1;

ll n, cnt[N];

vector <int> LPS(string s) {
    int n = s.length();
    vector <int> lps(n, 0);
    for (int i = 1; i < n; i++) {
        int j = lps[i-1];
        while(j > 0 && s[i] != s[j]) j = lps[j-1];
        if(s[i] == s[j]) j++;
        lps[i] = j;
        while(j > 0){
        	cnt[j]++;
        	j = lps[j - 1];
        }
    }
    return lps;
}

void solve(){
	string s;
	cin >> s;
	vector <int> lps = LPS(s);
	int j = lps[s.size() - 1];
	vpll ans;
	ans.pb({s.size(), 1});
	while(j){
		ans.pb({j, cnt[j] + 1});
		j = lps[j - 1];
	}
	reverse(all(ans));
	deb1(ans.size())
	for(auto it : ans) deb2(it.f, it.s)
}

int main(){
	GODSPEED;
	int test = 1;
	//cin >> test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}


#pragma GCC optimize "Ofast"
#pragma GCC optimize "unroll-loops"
#pragma GCC target "sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native"
#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define init(a, b) memset(a, b, sizeof(a))

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

#define MOD = 1e9+7;
#define MAXN = 2e5+5;

/******* Debugging Class Template *******/
#define DEBUG

#ifdef DEBUG

    #define debug(args...)     (Debugger()) , args

    class Debugger
    {
        public:
        Debugger(const std::string& _separator = " - ") :
        first(true), separator(_separator){}

        template<typename ObjectType> Debugger& operator , (const ObjectType& v)
        {
            if(!first)
                std:cerr << separator;
            std::cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std:cerr << endl;}

        private:
        bool first;
        std::string separator;
    };

#else
    #define debug(args...)                  // Just strip off all debug tokens
#endif

bool suff[100005];
int ct;

int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS
    string s;
    cin>>s;

    int n=s.length();
    int z[n];
    int dp[n+2];
    init(dp,0);
    for(int i=0,l=0,r=0;i<n;i++){
        if(i<=r)
            z[i]=min(r-i+1,z[i-l]);
        while(i+z[i]<n&&s[z[i]]==s[i+z[i]]) z[i]++;
        if(i+z[i]-1>r) l=i,r=i+z[i]-1;
        if(z[i]==n-i) suff[z[i]]=true,ct++;

        dp[z[i]]++;
    }

    for(int i=n-1;i>=0;i--) dp[i]+=dp[i+1];

    cout<<ct<<'\n';
    vpii res;
    for(int i=0;i<=n;i++){
        if(suff[i]) res.pb({i,dp[i]});
    }//cout<<dp[3];
    for(auto x:res){
        cout<<x.fi<<" "<<x.se<<'\n';
    }
    return 0;
}


#pragma GCC optimize "Ofast"
#pragma GCC optimize "unroll-loops"
#pragma GCC target "sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native"
#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define init(a, b) memset(a, b, sizeof(a))

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

#define MOD = 1e9+7;
#define MAXN = 2e5+5;

/******* Debugging Class Template *******/
#define DEBUG

#ifdef DEBUG

    #define debug(args...)     (Debugger()) , args

    class Debugger
    {
        public:
        Debugger(const std::string& _separator = " - ") :
        first(true), separator(_separator){}

        template<typename ObjectType> Debugger& operator , (const ObjectType& v)
        {
            if(!first)
                std:cerr << separator;
            std::cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std:cerr << endl;}

        private:
        bool first;
        std::string separator;
    };

#else
    #define debug(args...)                  // Just strip off all debug tokens
#endif

bool suff[100005];
int ct;

int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS
    string s;
    cin>>s;

    int n=s.length();
    int z[n];
    int dp[n+2];
    init(dp,0);
    init(z,0);
    for(int i=1,l=0,r=0;i<n;i++){
        if(i<=r)
            z[i]=min(r-i+1,z[i-l]);
        while(i+z[i]<n&&s[z[i]]==s[i+z[i]]) z[i]++;
        if(i+z[i]-1>r) l=i,r=i+z[i]-1;
        if(z[i]==n-i) suff[z[i]]=true,ct++;

        dp[z[i]]++;
    }

    for(int i=n-1;i>=0;i--) dp[i]+=dp[i+1];

    cout<<ct<<'\n';
    vector<pair<int,int>> res;
    for(int i=0;i<=n;i++){
        if(suff[i]) res.pb({i,dp[i]});
    }//cout<<dp[3];
    for(auto x:res){
        cout<<x.fi<<" "<<x.se<<'\n';
    }
    cout<<n<<" "<<1;
    return 0;
}


#pragma GCC optimize "Ofast"
#pragma GCC optimize "unroll-loops"
#pragma GCC target "sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native"
#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define init(a, b) memset(a, b, sizeof(a))

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

#define MOD = 1e9+7;
#define MAXN = 2e5+5;

/******* Debugging Class Template *******/
#define DEBUG

#ifdef DEBUG

    #define debug(args...)     (Debugger()) , args

    class Debugger
    {
        public:
        Debugger(const std::string& _separator = " - ") :
        first(true), separator(_separator){}

        template<typename ObjectType> Debugger& operator , (const ObjectType& v)
        {
            if(!first)
                std:cerr << separator;
            std::cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std:cerr << endl;}

        private:
        bool first;
        std::string separator;
    };

#else
    #define debug(args...)                  // Just strip off all debug tokens
#endif

bool suff[100005];
int ct;

int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS
    string s;
    cin>>s;

    int n=s.length();
    int z[n];
    int dp[n+2];
    init(dp,0);
    init(z,0);
    for(int i=0,l=0,r=0;i<n;i++){
        if(i<=r)
            z[i]=min(r-i+1,z[i-l]);
        while(i+z[i]<n&&s[z[i]]==s[i+z[i]]) z[i]++;
        if(i+z[i]-1>r) l=i,r=i+z[i]-1;
        if(z[i]==n-i) suff[z[i]]=true,ct++;

        dp[z[i]]++;
    }

    for(int i=n-1;i>=0;i--) dp[i]+=dp[i+1];

    cout<<ct<<'\n';
    vector<pair<int,int>> res;
    for(int i=0;i<=n;i++){
        if(suff[i]) res.pb({i,dp[i]});
    }//cout<<dp[3];
    for(auto x:res){
        cout<<x.fi<<" "<<x.se<<'\n';
    }
    return 0;
}


#pragma GCC optimize "Ofast"
#pragma GCC optimize "unroll-loops"
#pragma GCC target "sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native"
#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define init(a, b) memset(a, b, sizeof(a))

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

#define MOD = 1e9+7;
#define MAXN = 2e5+5;

/******* Debugging Class Template *******/
#define DEBUG

#ifdef DEBUG

    #define debug(args...)     (Debugger()) , args

    class Debugger
    {
        public:
        Debugger(const std::string& _separator = " - ") :
        first(true), separator(_separator){}

        template<typename ObjectType> Debugger& operator , (const ObjectType& v)
        {
            if(!first)
                std:cerr << separator;
            std::cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std:cerr << endl;}

        private:
        bool first;
        std::string separator;
    };

#else
    #define debug(args...)                  // Just strip off all debug tokens
#endif

long long n,i,j,r,k,l,z[100007],d[100007],cnt;
string s;
bool suffix[100007];
vector<pair<long long ,long long> >v;

int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

    cin>>s;n=s.length();

    for(i=1,l=0,r=0;i<n;i++)
    {
        if(i<=r) z[i]=min(r-i+1,z[i-l]);

        while(i+z[i]<n && s[z[i]]==s[i+z[i]]) z[i]++;

        if(i+z[i]-1>r) l=i,r=i+z[i]-1;

        if(i+z[i]==n) suffix[z[i]]=true;

        d[z[i]]++;
    }
    for(i=n-1;i>=0;i--) d[i]+=d[i+1];

    for(i=1;i<=n;i++) if(suffix[i]) v.push_back({i,d[i]});

    cout<<v.size()+1<<"\n";

    for(i=0;i<v.size();i++) cout<<v[i].first<<"  "<<v[i].second+1<<"\n";

    cout<<n<<"  "<<1;
}


#pragma GCC optimize "Ofast"
#pragma GCC optimize "unroll-loops"
#pragma GCC target "sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native"
#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define init(a, b) memset(a, b, sizeof(a))

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

#define MOD = 1e9+7;
#define MAXN = 2e5+5;

/******* Debugging Class Template *******/
#define DEBUG

#ifdef DEBUG

    #define debug(args...)     (Debugger()) , args

    class Debugger
    {
        public:
        Debugger(const std::string& _separator = " - ") :
        first(true), separator(_separator){}

        template<typename ObjectType> Debugger& operator , (const ObjectType& v)
        {
            if(!first)
                std:cerr << separator;
            std::cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std:cerr << endl;}

        private:
        bool first;
        std::string separator;
    };

#else
    #define debug(args...)                  // Just strip off all debug tokens
#endif

vi zfunction(string s){
    int n=s.length();
    vi z(n);
    for(int i=1,l=0,r=0;i<n;i++){
        if(i<=r)
            z[i]=min(r-i+1,z[i-l]);
        while(i+z[i]<n&&s[z[i]]==s[i+z[i]]) z[i]++;
        if(i+z[i]-1>r) l=i,r=i+z[i]-1;
    }
    //for(auto x:z) cout<<x<<" ";
    return z;
}

int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS
    string s;
    cin>>s;
    vi z =zfunction(s);
    map<int,int>mp;
    int k=0;
    int n=s.length();

    vi res[10005];
    unordered_map<int,int> x;
    for(int i=0;i<n;i++){
        if(z[i]+i==n){
            mp[z[i]]++;

            k++;

        }
         x[z[i]]++;
    }

    cout<<k+1<<'\n';
    int to=0;
    vpii xx;
    for(auto it=mp.rbegin();it!=mp.rend();it++){
        to+=x[it->first];
        //cout<<it->first<<" "<<to<<'\n';
        xx.pb({it->first,to});
    }
    sort(xx.begin(),xx.end());
    for(auto q :xx){
        cout<<q.fi<<" "<<q.se+1<<'\n';
    }
    cout<<n<<" "<<1;
    return 0;
}


#pragma GCC optimize "Ofast"
#pragma GCC optimize "unroll-loops"
#pragma GCC target "sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native"
#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define init(a, b) memset(a, b, sizeof(a))

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

#define MOD = 1e9+7;
#define MAXN = 2e5+5;

/******* Debugging Class Template *******/
#define DEBUG

#ifdef DEBUG

    #define debug(args...)     (Debugger()) , args

    class Debugger
    {
        public:
        Debugger(const std::string& _separator = " - ") :
        first(true), separator(_separator){}

        template<typename ObjectType> Debugger& operator , (const ObjectType& v)
        {
            if(!first)
                std:cerr << separator;
            std::cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std:cerr << endl;}

        private:
        bool first;
        std::string separator;
    };

#else
    #define debug(args...)                  // Just strip off all debug tokens
#endif

int dp[100005];
bool suff[100005];
int ct;

int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS
    string s;
    cin>>s;

    int n=s.length();
    vi z(n);
    for(int i=1,l=0,r=0;i<n;i++){
        if(i<=r)
            z[i]=min(r-i+1,z[i-l]);
        while(i+z[i]<n&&s[z[i]]==s[i+z[i]]) z[i]++;
        if(i+z[i]-1>r) l=i,r=i+z[i]-1;
        if(z[i]==n-i) suff[z[i]]=true,ct++;

        dp[z[i]]++;
    }

    for(int i=n-1;i>=0;i--) dp[i]+=dp[i+1];

    cout<<ct<<'\n';
    vpii res;
    for(int i=0;i<=n;i++){
        if(suff[i]) res.pb({i,dp[i]});
    }//cout<<dp[3];
    for(auto x:res){
        cout<<x.fi<<" "<<x.se<<'\n';
    }
    return 0;
}


#pragma GCC optimize "Ofast"
#pragma GCC optimize "unroll-loops"
#pragma GCC target "sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native"
#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define init(a, b) memset(a, b, sizeof(a))

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

#define MOD = 1e9+7;
#define MAXN = 2e5+5;

/******* Debugging Class Template *******/
#define DEBUG

#ifdef DEBUG

    #define debug(args...)     (Debugger()) , args

    class Debugger
    {
        public:
        Debugger(const std::string& _separator = " - ") :
        first(true), separator(_separator){}

        template<typename ObjectType> Debugger& operator , (const ObjectType& v)
        {
            if(!first)
                std:cerr << separator;
            std::cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std:cerr << endl;}

        private:
        bool first;
        std::string separator;
    };

#else
    #define debug(args...)                  // Just strip off all debug tokens
#endif

bool suff[100005];
int ct;

int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS
    string s;
    cin>>s;

    int n=s.length();
    int z[n];
    int dp[n+2];
    init(dp,0);
    init(z,0);
    for(int i=1,l=0,r=0;i<n;i++){
        if(i<=r)
            z[i]=min(r-i+1,z[i-l]);
        while(i+z[i]<n&&s[z[i]]==s[i+z[i]]) z[i]++;
        if(i+z[i]-1>r) l=i,r=i+z[i]-1;
        if(z[i]==n-i) suff[z[i]]=true,ct++;

        dp[z[i]]++;
    }

    for(int i=n-1;i>=0;i--) dp[i]+=dp[i+1];

    cout<<ct<<'\n';
    vector<pair<int,int>> res;
    for(int i=0;i<=n;i++){
        if(suff[i]) res.pb({i,dp[i]});
    }//cout<<dp[3];
    for(auto x:res){
        cout<<x.fi<<" "<<x.se+1<<'\n';
    }
    cout<<n<<" "<<1;
    return 0;
}


#pragma GCC optimize "Ofast"
#pragma GCC optimize "unroll-loops"
#pragma GCC target "sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native"
#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define init(a, b) memset(a, b, sizeof(a))

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

#define MOD = 1e9+7;
#define MAXN = 2e5+5;

/******* Debugging Class Template *******/
#define DEBUG

#ifdef DEBUG

    #define debug(args...)     (Debugger()) , args

    class Debugger
    {
        public:
        Debugger(const std::string& _separator = " - ") :
        first(true), separator(_separator){}

        template<typename ObjectType> Debugger& operator , (const ObjectType& v)
        {
            if(!first)
                std:cerr << separator;
            std::cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std:cerr << endl;}

        private:
        bool first;
        std::string separator;
    };

#else
    #define debug(args...)                  // Just strip off all debug tokens
#endif

int dp[100005];
bool suff[100005];
int ct;

int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS
    string s;
    cin>>s;

    int n=s.length();
    vi z(n);
    for(int i=0,l=0,r=0;i<n;i++){
        if(i<=r)
            z[i]=min(r-i+1,z[i-l]);
        while(i+z[i]<n&&s[z[i]]==s[i+z[i]]) z[i]++;
        if(i+z[i]-1>r) l=i,r=i+z[i]-1;
        if(z[i]==n-i) suff[z[i]]=true,ct++;

        dp[z[i]]++;
    }

    for(int i=n-1;i>=0;i--) dp[i]+=dp[i+1];

    cout<<ct<<'\n';
    vpii res;
    for(int i=0;i<=n;i++){
        if(suff[i]) res.pb({i,dp[i]});
    }//cout<<dp[3];
    for(auto x:res){
        cout<<x.fi<<" "<<x.se<<'\n';
    }
    return 0;
}


#pragma GCC optimize "Ofast"
#pragma GCC optimize "unroll-loops"
#pragma GCC target "sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native"
#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define init(a, b) memset(a, b, sizeof(a))

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

#define MOD = 1e9+7;
#define MAXN = 2e5+5;

/******* Debugging Class Template *******/
#define DEBUG

#ifdef DEBUG

    #define debug(args...)     (Debugger()) , args

    class Debugger
    {
        public:
        Debugger(const std::string& _separator = " - ") :
        first(true), separator(_separator){}

        template<typename ObjectType> Debugger& operator , (const ObjectType& v)
        {
            if(!first)
                std:cerr << separator;
            std::cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std:cerr << endl;}

        private:
        bool first;
        std::string separator;
    };

#else
    #define debug(args...)                  // Just strip off all debug tokens
#endif

vi zfunction(string s){
    int n=s.length();
    vi z(n);
    for(int i=0,l=0,r=0;i<n;i++){
        if(i<=r)
            z[i]=min(r-i+1,z[i-l]);
        while(i+z[i]<n&&s[z[i]]==s[i+z[i]]) z[i]++;
        if(i+z[i]-1>r) l=i,r=i+z[i]-1;
    }
    //for(auto x:z) cout<<x<<" ";
    return z;
}

int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS
    string s;
    cin>>s;
    vi z =zfunction(s);
    map<int,int>mp;
    int k=0;
    int n=s.length();

    vi res[10005];
    unordered_map<int,int> x;
    for(int i=0;i<n;i++){
        if(z[i]+i==n){
            mp[z[i]]++;

            k++;

        }
         x[z[i]]++;
    }

    cout<<k<<'\n';
    int to=0;
    for(auto it=mp.rbegin();it!=mp.rend();it++){
        to+=x[it->first];
        cout<<it->first<<" "<<to<<'\n';

    }
    return 0;
}


#pragma GCC optimize "Ofast"
#pragma GCC optimize "unroll-loops"
#pragma GCC target "sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native"
#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define init(a, b) memset(a, b, sizeof(a))

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

#define MOD = 1e9+7;
#define MAXN = 2e5+5;

/******* Debugging Class Template *******/
#define DEBUG

#ifdef DEBUG

    #define debug(args...)     (Debugger()) , args

    class Debugger
    {
        public:
        Debugger(const std::string& _separator = " - ") :
        first(true), separator(_separator){}

        template<typename ObjectType> Debugger& operator , (const ObjectType& v)
        {
            if(!first)
                std:cerr << separator;
            std::cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std:cerr << endl;}

        private:
        bool first;
        std::string separator;
    };

#else
    #define debug(args...)                  // Just strip off all debug tokens
#endif

vi zfunction(string s){
    int n=s.length();
    vi z(n);
    for(int i=0,l=0,r=0;i<n;i++){
        if(i<=r)
            z[i]=min(r-i+1,z[i-l]);
        while(i+z[i]<n&&s[z[i]]==s[i+z[i]]) z[i]++;
        if(i+z[i]-1>r) l=i,r=i+z[i]-1;
    }
    //for(auto x:z) cout<<x<<" ";
    return z;
}

int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS
    string s;
    cin>>s;
    vi z =zfunction(s);
    map<int,int>mp;
    int k=0;
    int n=s.length();

    vi res[10005];
    unordered_map<int,int> x;
    for(int i=0;i<n;i++){
        if(z[i]+i==n){
            mp[z[i]]++;

            k++;

        }
         x[z[i]]++;
    }

    cout<<k<<'\n';
    int to=0;
    vpii xx;
    for(auto it=mp.rbegin();it!=mp.rend();it++){
        to+=x[it->first];
        //cout<<it->first<<" "<<to<<'\n';
        xx.pb({it->first,to});
    }
    sort(xx.begin(),xx.end());
    for(auto q :xx){
        cout<<q.fi<<" "<<q.se<<'\n';
    }
    return 0;
}


#pragma GCC optimize "Ofast"
#pragma GCC optimize "unroll-loops"
#pragma GCC target "sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native"
#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define init(a, b) memset(a, b, sizeof(a))

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

#define MOD = 1e9+7;
#define MAXN = 2e5+5;

/******* Debugging Class Template *******/
#define DEBUG

#ifdef DEBUG

    #define debug(args...)     (Debugger()) , args

    class Debugger
    {
        public:
        Debugger(const std::string& _separator = " - ") :
        first(true), separator(_separator){}

        template<typename ObjectType> Debugger& operator , (const ObjectType& v)
        {
            if(!first)
                std:cerr << separator;
            std::cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std:cerr << endl;}

        private:
        bool first;
        std::string separator;
    };

#else
    #define debug(args...)                  // Just strip off all debug tokens
#endif

bool suff[100005];
int ct;

int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS
    string s;
    cin>>s;

    int n=s.length();
    int z[n];
    int dp[n+2];
    init(dp,0);
    init(z,0);
    for(int i=1,l=0,r=0;i<n;i++){
        if(i<=r)
            z[i]=min(r-i+1,z[i-l]);
        while(i+z[i]<n&&s[z[i]]==s[i+z[i]]) z[i]++;
        if(i+z[i]-1>r) l=i,r=i+z[i]-1;
        if(z[i]==n-i) suff[z[i]]=true,ct++;

        dp[z[i]]++;
    }

    for(int i=n-1;i>=0;i--) dp[i]+=dp[i+1];

    cout<<ct+1<<'\n';
    vpii res;
    for(int i=0;i<=n;i++){
        if(suff[i]) res.pb({i,dp[i]});
    }//cout<<dp[3];
    for(auto x:res){
        cout<<x.fi<<" "<<x.se+1<<'\n';
    }
    cout<<n<<" "<<1;
    return 0;
}


#pragma GCC optimize "Ofast"
#pragma GCC optimize "unroll-loops"
#pragma GCC target "sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native"
#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define init(a, b) memset(a, b, sizeof(a))

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

#define MOD = 1e9+7;
#define MAXN = 2e5+5;

/******* Debugging Class Template *******/
#define DEBUG

#ifdef DEBUG

    #define debug(args...)     (Debugger()) , args

    class Debugger
    {
        public:
        Debugger(const std::string& _separator = " - ") :
        first(true), separator(_separator){}

        template<typename ObjectType> Debugger& operator , (const ObjectType& v)
        {
            if(!first)
                std:cerr << separator;
            std::cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std:cerr << endl;}

        private:
        bool first;
        std::string separator;
    };

#else
    #define debug(args...)                  // Just strip off all debug tokens
#endif

bool suff[100005];
int ct;

int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS
    string s;
    cin>>s;

    int n=s.length();
    int z[n];
    int dp[n+2];
    init(dp,0);
    init(z,0);
    for(int i=1,l=0,r=0;i<n;i++){
        if(i<=r)
            z[i]=min(r-i+1,z[i-l]);
        while(i+z[i]<n&&s[z[i]]==s[i+z[i]]) z[i]++;
        if(i+z[i]-1>r) l=i,r=i+z[i]-1;
        if(z[i]==n-i) suff[z[i]]=true,ct++;

        dp[z[i]]++;
    }

    for(int i=n-1;i>=0;i--) dp[i]+=dp[i+1];

    cout<<ct+1<<'\n';
    vector<pair<int,int>> res;
    for(int i=0;i<=n;i++){
        if(suff[i]) res.pb({i,dp[i]});
    }//cout<<dp[3];
    for(auto x:res){
        cout<<x.fi<<" "<<x.se+1<<'\n';
    }
    cout<<n<<" "<<1;
    return 0;
}


#pragma GCC optimize "Ofast"
#pragma GCC optimize "unroll-loops"
#pragma GCC target "sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native"
#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define init(a, b) memset(a, b, sizeof(a))

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

#define MOD = 1e9+7;
#define MAXN = 2e5+5;

/******* Debugging Class Template *******/
#define DEBUG

#ifdef DEBUG

    #define debug(args...)     (Debugger()) , args

    class Debugger
    {
        public:
        Debugger(const std::string& _separator = " - ") :
        first(true), separator(_separator){}

        template<typename ObjectType> Debugger& operator , (const ObjectType& v)
        {
            if(!first)
                std:cerr << separator;
            std::cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std:cerr << endl;}

        private:
        bool first;
        std::string separator;
    };

#else
    #define debug(args...)                  // Just strip off all debug tokens
#endif

int dp[100005];
bool suff[100005];
int ct;
vi zfunction(string s){
    int n=s.length();
    vi z(n);
    for(int i=0,l=0,r=0;i<n;i++){
        if(i<=r)
            z[i]=min(r-i+1,z[i-l]);
        while(i+z[i]<n&&s[z[i]]==s[i+z[i]]) z[i]++;
        if(i+z[i]-1>r) l=i,r=i+z[i]-1;
        if(z[i]==n-i) suff[z[i]]=true,ct++;

        dp[z[i]]++;
    }
    //cout<<dp[7];
    //for(auto x:z) cout<<x<<" ";
    return z;
}

int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS
    string s;
    cin>>s;
    vi z =zfunction(s);
    int n=s.length();

    for(int i=n-1;i>=0;i--) dp[i]+=dp[i+1];

    cout<<ct<<'\n';
    vpii res;
    for(int i=0;i<=n;i++){
        if(suff[i]) res.pb({i,dp[i]});
    }//cout<<dp[3];
    for(auto x:res){
        cout<<x.fi<<" "<<x.se<<'\n';
    }
    return 0;
}


#pragma GCC optimize "Ofast"
#pragma GCC optimize "unroll-loops"
#pragma GCC target "sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native"
#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define init(a, b) memset(a, b, sizeof(a))

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

#define MOD = 1e9+7;
#define MAXN = 2e5+5;

/******* Debugging Class Template *******/
#define DEBUG

#ifdef DEBUG

    #define debug(args...)     (Debugger()) , args

    class Debugger
    {
        public:
        Debugger(const std::string& _separator = " - ") :
        first(true), separator(_separator){}

        template<typename ObjectType> Debugger& operator , (const ObjectType& v)
        {
            if(!first)
                std:cerr << separator;
            std::cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std:cerr << endl;}

        private:
        bool first;
        std::string separator;
    };

#else
    #define debug(args...)                  // Just strip off all debug tokens
#endif

bool suff[100005];
int ct;

int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS
    string s;
    cin>>s;

    int n=s.length();
    int z[n];
    int dp[n+2];
    init(dp,0);
    init(z,0);
    for(int i=0,l=0,r=0;i<n;i++){
        if(i<=r)
            z[i]=min(r-i+1,z[i-l]);
        while(i+z[i]<n&&s[z[i]]==s[i+z[i]]) z[i]++;
        if(i+z[i]-1>r) l=i,r=i+z[i]-1;
        if(z[i]==n-i) suff[z[i]]=true,ct++;

        dp[z[i]]++;
    }

    for(int i=n-1;i>=0;i--) dp[i]+=dp[i+1];

    cout<<ct<<'\n';
    vpii res;
    for(int i=0;i<=n;i++){
        if(suff[i]) res.pb({i,dp[i]});
    }//cout<<dp[3];
    for(auto x:res){
        cout<<x.fi<<" "<<x.se<<'\n';
    }
    return 0;
}


// Z algorithm , (string processing )
// https://cp-algorithms.com/string/z-function.html
// https://codeforces.com/blog/entry/3107
#include <bits/stdc++.h>
using namespace std;
const int sz=1e5+5;
int z[sz]={0};
void z_function(string s) {
    int n = (int) s.length();
    for (int i = 0, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
}
int main()
{
    string s;
    cin>>s;
    z_function(s);
    /*
    for(int i=0; i<s.size(); i++)
        cout<<z[i]<<" ";
    cout<< endl;

    for(int i=0; i<n; i++) // index i to save in it max number of char to match with prefix of s
    {
        // initial value could considered to be some huristic
        int j=0;
        if(i<=r){ // save us from going throw same chars again
            j=min(z[i-l] , r-i+1); //number of matched elements is the index for the naive loop.
            z[i]=min(z[i-l] , r-i+1); //number of matched elements is the index for the naive loop.
        }
        for(; j<n && i+j<n; j++)  // naive algorithm
        {
            if(s[i+j]!=s[j])
                break;
            z[i]++; // matched
            op++;
        }
        if(i+z[i]-1>=r){ // edit the most right seg
            l=i;
            r=z[i]+i-1;  // included
        }
    }
    */
    vector<int> v , le;
    //le.push_back(s.size());
    //v.push_back(s.size());
    for(int i=0; i<s.size(); i++)
    {
        v.push_back(z[i]);
        if(z[i]+i==s.size())
            le.push_back(z[i]);
    }
    // this brilliant idea is not mine
    cout<<le.size()<< endl;
    sort(v.begin() , v.end());
    sort(le.begin() , le.end());
    for(int i=0; i<le.size(); i++)
    {
        int c=lower_bound(v.begin() , v.end() , le[i])-v.begin();
        cout<<le[i]<<" "<<v.size()-c<< endl;
    }
    return 0;
}


#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int n;
vector <pair<int,string> > g[100013];

int ans;
char ch[300013];
int   f[300013];

string p;
int pn;
int  fp[300013];

void dfs(int v, int cnt){
	for (int u=0;u<(int)g[v].size();u++){
		string s=g[v][u].second;
		int to=g[v][u].first;
		int sn=s.size();
		for (int i=0;i<sn;i++){
			int j=cnt+i;
			ch[j]=s[i];
			int k=j==0?0:f[j-1];
			while (k>0 && ch[j]!=p[k]){
				k=fp[k-1];
			}
			if (ch[j]==p[k]){
				k++;
			}
			if (k==p.size()){
				ans++;
				k=fp[k-1];
			}
			f[j]=k;
		}
		dfs(to,cnt+sn);
	}
}

int main(){
	cin>>n;
	for (int i=1;i<n;i++){
		int t;
		string s;
		cin>>t>>s;
		t--;
		g[t].push_back(make_pair(i,s));
	}

	cin>>p;
	pn=p.size();
	fp[0]=0;
	for (int i=1;i<pn;i++){
		int k=fp[i-1];
		while (k>0 && p[k]!=p[i]){
			k=fp[k-1];
		}
		if (p[k]==p[i]) k++;
		fp[i]=k;
	}

	ans=0;
	dfs(0,0);
	cout<<ans;
	return 0;
}


#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll __int64
#define ls rt<<1
#define rs ls|1
#define lson l,mid,ls
#define rson mid+1,r,rs
#define middle (l+r)>>1
#define clr_all(x,c) memset(x,c,sizeof(x))
#define clr(x,c,n) memset(x,c,sizeof(x[0])*(n+1))
#define eps (1e-8)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define PI (acos(-1.0))
#pragma comment(linker, "/STACK:102400000,102400000")
template <class T> T _max(T x,T y){return x>y? x:y;}
template <class T> T _min(T x,T y){return x<y? x:y;}
template <class T> T _abs(T x){return (x < 0)? -x:x;}
template <class T> T _mod(T x,T y){return (x > 0)? x%y:((x%y)+y)%y;}
template <class T> void _swap(T &x,T &y){T t=x;x=y;y=t;}
template <class T> void getmax(T& x,T y){x=(y > x)? y:x;}
template <class T> void getmin(T& x,T y){x=(x<0 || y<x)? y:x;}
int TS,cas=1;
const int M=100000+5;
int n,ret;
int fa[M],v[M],nxt[M];
string str[M],pat;
int jump[M],pLen;
void getJump(){
    jump[0]=-1;
    for(int i=1,j=-1;i<pLen;i++){
        while(j!=-1 && pat[j+1]!=pat[i]) j=jump[j];
        jump[i]= (pat[j+1]==pat[i])? ++j:j;
    }
}

void dfs(int u,int pos){
    for(int p=fa[u];p!=-1;p=nxt[p]){
        int i,j=pos;
        for(i=0;i<str[p].length();i++){
            while(j!=-1 && pat[j+1]!=str[p][i]) j=jump[j];
            if(pat[j+1] == str[p][i]) j++;
            if(j+1 == pLen) j=jump[j],ret++;
        }
        dfs(v[p],j);
    }
}

void run(){
    int i,j;
    for(i=1;i<=n;i++) fa[i]=-1;
    for(i=2;i<=n;i++){
        cin>>j>>str[i];
        nxt[i]=fa[j],v[i]=i,fa[j]=i;
    }
    cin>>pat;
    pLen=pat.length();
    getJump();
    ret=0;
    dfs(1,-1);
    printf("%d\n",ret);
}

void preSof(){
}

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    preSof();
    //run();
    while((~scanf("%d",&n))) run();
    //for(scanf("%d",&TS);cas<=TS;cas++) run();
    return 0;
}


#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll __int64
#define ls rt<<1
#define rs ls|1
#define lson l,mid,ls
#define rson mid+1,r,rs
#define middle (l+r)>>1
#define clr_all(x,c) memset(x,c,sizeof(x))
#define clr(x,c,n) memset(x,c,sizeof(x[0])*(n+1))
#define eps (1e-8)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define PI (acos(-1.0))
#pragma comment(linker, "/STACK:102400000,102400000")
template <class T> T _max(T x,T y){return x>y? x:y;}
template <class T> T _min(T x,T y){return x<y? x:y;}
template <class T> T _abs(T x){return (x < 0)? -x:x;}
template <class T> T _mod(T x,T y){return (x > 0)? x%y:((x%y)+y)%y;}
template <class T> void _swap(T &x,T &y){T t=x;x=y;y=t;}
template <class T> void getmax(T& x,T y){x=(y > x)? y:x;}
template <class T> void getmin(T& x,T y){x=(x<0 || y<x)? y:x;}
int TS,cas=1;
const int M=100000+5;
int n,ret;
int fa[M],v[M],nxt[M];
string str[M],pat;
int jump[M],pLen;
void getJump(){
    jump[0]=-1;
    for(int i=1,j=-1;i<pLen;i++){
        while(j!=-1 && pat[j+1]!=pat[i]) j=jump[j];
        jump[i]= (pat[j+1]==pat[i])? ++j:j;
    }
}

void dfs(int u,int pos){
    for(int p=fa[u];p!=-1;p=nxt[p]){
        int i,j=pos;
        for(i=0;i<str[p].length();i++){
            while(j!=-1 && pat[j+1]!=str[p][i]) j=jump[j];
            if(pat[j+1] == str[p][i]) j++;
            if(j+1 == pLen) j=jump[j],ret++;
        }
        dfs(v[p],j);
    }
}

void run(){
    int i,j;
    for(i=1;i<=n;i++) fa[i]=-1;
    for(i=2;i<=n;i++){
        cin>>j>>str[i];
        nxt[i]=fa[j],v[i]=i,fa[j]=i;
    }
    cin>>pat;
    pLen=pat.length();
    getJump();
    ret=0;
    dfs(1,0);
    printf("%d\n",ret);
}

void preSof(){
}

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    preSof();
    //run();
    while((~scanf("%d",&n))) run();
    //for(scanf("%d",&TS);cas<=TS;cas++) run();
    return 0;
}


#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#include <cstring>
#include <iostream>
using namespace std;
#pragma comment(linker, "/STACK:167772160")

typedef long long ll;
typedef pair<int, int> pii;

const int INF = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.);

char str[600600];
int p[600600];
int l = 0;
int patlen = 0;
int ans = 0;

void add(char c)
{
    str[l] = c;
    int pos = l;
    ++l;
    if (pos == 0)
    {
        p[pos] = 0;
        return;
    }
    int j = p[pos - 1];
    while (j > 0 && str[pos] != str[j])
        j = p[j-1];
    if (str[pos] == str[j])  ++j;
    p[pos] = j;
    if (j >= patlen)
        ++ans;
}

vector<int> G[100500];
string S[100500];
char buff[500500];

void dfs(int v)
{
    for (int i = 0; i < G[v].size(); ++i)
    {
        int nxt = G[v][i];
        for (int j = 0; j < S[nxt].length(); ++j)
        {
            add(S[nxt][j]);
        }
        dfs(nxt);
        l -= S[nxt].length();
    }
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("test.txt", "r", stdin);
#endif

    int N;
    scanf("%d", &N);
    for (int i = 1; i < N; ++i)
    {
        int p;
        scanf("%d %s", &p, buff);
        --p;
        G[p].push_back(i);
        S[i] = buff;
    }
    scanf("%s", buff);
    int len = strlen(buff);
    patlen = len;
    for (int i = 0; i < len; ++i)
        add(buff[i]);
    add('$');
    dfs(0);
    printf("%d\n", ans);
	return 0;
}


#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <ctime>
#include <complex>

using namespace std;

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define x first
#define y second
#define sqr(x) (((x) + .0) * ((x) + .0))

typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<db, db> pt;

const int maxn = 100500;
const int infi = (1 << 30);
const ll infl = (1LL << 62);
const db eps = 1e-9;
const ll mod = 1000000007LL;
const db pi = acos(-1.0);

int n, len;
string s;
vector< pair<int, string> > g[maxn];
vector<int> p;
ll ans;

void dfs(int v, int pos) {
    for (int i = pos; i < s.length(); i++) {
        int j = p[i - 1];
        while (j > 0 && s[i] != s[j])
            j = p[j - 1];
        if (s[i] == s[j])
            j++;
        p[i] = j;
        if (j == len)
            ans++;
    }
    int m = s.length();
    for (int i = 0; i < g[v].size(); i++) {
        s = s + g[v][i].y;
        dfs(g[v][i].x, m);
        s.erase(m, g[v][i].y.length());
    }
}

int main() {

    cin >> n;
    for (int i = 1; i < n; i++) {
        int cp;
        string cs;
        cin >> cp >> cs;
        cp--;
        g[cp].pb(mp(i, cs));
    }
    cin >> s;
    len = s.length();
    s.pb('#');
    p.resize(maxn * 3, 0);
    dfs(0, 1);
    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <ctime>
#include <complex>

using namespace std;

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define x first
#define y second
#define sqr(x) (((x) + .0) * ((x) + .0))

typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<db, db> pt;

const int maxn = 100500;
const int infi = (1 << 30);
const ll infl = (1LL << 62);
const db eps = 1e-9;
const ll mod = 1000000007LL;
const db pi = acos(-1.0);

int n, len;
string s;
vector< pair<int, string> > g[maxn];
vector<int> p;
vector<char> t;
ll ans;

void dfs(int v, int pos) {
    for (int i = pos; i < t.size(); i++) {
        int j = p[i - 1];
        while (j > 0 && t[i] != t[j])
            j = p[j - 1];
        if (t[i] == t[j])
            j++;
        p[i] = j;
        if (j == len)
            ans++;
    }
    int m = t.size();
    for (int i = 0; i < g[v].size(); i++) {
        for (int j = 0; j < g[v][i].y.length(); j++)
            t.pb(g[v][i].y[j]);
        dfs(g[v][i].x, m);
        for (int j = 0; j < g[v][i].y.length(); j++)
            t.ppb();
    }
}

int main() {

    cin >> n;
    for (int i = 1; i < n; i++) {
        int cp;
        string cs;
        cin >> cp >> cs;
        cp--;
        g[cp].pb(mp(i, cs));
    }
    cin >> s;
    len = s.length();
    s.pb('#');
    for (int i = 0; i < s.length(); i++)
        t.pb(s[i]);
    p.resize(maxn * 3, 0);
    dfs(0, 1);
    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <ctime>
#include <complex>

using namespace std;

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define x first
#define y second
#define sqr(x) (((x) + .0) * ((x) + .0))

typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<db, db> pt;

const int maxn = 100500;
const int infi = (1 << 30);
const ll infl = (1LL << 62);
const db eps = 1e-9;
const ll mod = 1000000007LL;
const db pi = acos(-1.0);

int n;
string s;
vector< pair<int, string> > g[maxn];
vector<int> p;
ll ans;

void dfs(int v, string t, int pos) {
    for (int i = pos; i < t.length(); i++) {
        int j = p[i - 1];
        while (j > 0 && t[i] != t[j])
            j = p[j - 1];
        if (t[i] == t[j])
            j++;
        p[i] = j;
        if (j == s.length() - 1)
            ans++;
    }
    for (int i = 0; i < g[v].size(); i++) {
        int u = g[v][i].x;
        dfs(u, t + g[v][i].y, t.length());
    }
}

int main() {

    cin >> n;
    for (int i = 1; i < n; i++) {
        int cp;
        string cs;
        cin >> cp >> cs;
        cp--;
        g[cp].pb(mp(i, cs));
    }
    cin >> s;
    s.pb('#');
    p.resize(maxn * 3, 0);
    dfs(0, s, 1);
    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <utility>
#include <iomanip>

using namespace std;

int n, p, len;
vector < pair <int, string> > g[105000];
string s;
vector <char> a;
int pi[500000];
long long ans = 0;

void dfs(int v) {
	for (int i = 0; i < (int)g[v].size(); i++) {
		int to = g[v][i].first;
		int cur = (int)a.size(), clen = (int)g[v][i].second.length();
		for (int j = 0; j < clen; j++)
			a.push_back(g[v][i].second[j]);

		for (int j = cur; j < cur + clen; j++) {
			if (j == 0) {
				pi[j] = 0;
				continue;
			}
			int k = pi[j - 1];
			while (k > 0 && a[j] != a[k])
				k = pi[k - 1];
			if (a[j] == a[k])
				k++;
			pi[j] = k;
			if (pi[j] == len)
				ans++;
		}

		dfs(to);

		for (int i = 0; i < clen; i++)
			a.pop_back();
	}
}

int main() {
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	scanf("%d\n", &n);
	for (int i = 2; i <= n; i++) {
		scanf("%d ", &p);
		getline(cin, s);
		g[p].push_back(make_pair(i, s));
	}
	getline(cin, s);
	len = s.length();

	g[0].push_back(make_pair(1, s + "$"));

	dfs(0);

	cout << ans;

	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

typedef unsigned int uint;
const uint base1=257, base2=263;
uint bp1[300100];
uint bp2[300100];

class HashString
{
	string s;
	vector<uint> hash1;
	vector<uint> hash2;
public:
	HashString(){}
	HashString(string _s)
	{
		setString (_s);
	}

	void setString (const string& _s)
	{
		s=_s;
		hash1.assign (s.size(),0);
		hash2.assign (s.size(),0);
		hash1[0]=(uint)s[0];
		hash2[0]=(uint)s[0];
		for (int i=1;i<s.size();i++)
		{
			hash1[i]=hash1[i-1]+bp1[i]*(uint)s[i];
			hash2[i]=hash2[i-1]+bp2[i]*(uint)s[i];
		}
	}

	int Length() const { return s.size(); }

	bool isEqual (int from_this, const HashString& other, int from_other, int len)
	{
//		if (from_this + len > s.size() || from_other+len>other.s.size()) return false;
		if ((hash1[from_this+len-1]-(from_this?hash1[from_this-1]:0)) * bp1[from_other] !=
			(other.hash1[from_other+len-1]-(from_other?other.hash1[from_other-1]:0)) * bp1[from_this] ||
			(hash2[from_this+len-1]-(from_this?hash2[from_this-1]:0)) * bp2[from_other] !=
			(other.hash2[from_other+len-1]-(from_other?other.hash2[from_other-1]:0)) * bp2[from_this])
			return false;
		return true;
/*		int i;
		for (i=0;i<len && s[from_this++]==other.s[from_other++];i++);
		return i==len;
*/
	}
};

struct Node
{
	int parent;
	vector<int> childs;
	HashString s;
};

Node nodes[100100];
char buf[300100];

int main ()
{
//	freopen ("input.txt","rt",stdin);
//	freopen ("output.txt","wt",stdout);
	int i,j,k,m,n;

/*
	printf ("100000\n");
	for (i=2;i<=100000;i++)
	{
		printf ("%d ",i-1);
		for (j=0;j<2;j++) printf ("%c",'a'+rand()%2);
		printf ("\n");
	}
*/
	bp1[0]=bp2[0]=1;
	for (i=1;i<300100;i++){ bp1[i]=bp1[i-1]*base1, bp2[i]=bp2[i-1]*base2; }

	scanf ("%d",&n);
	nodes[1].s.setString("#");
	for (i=2;i<=n;i++)
	{
		scanf ("%d %s",&m,buf);
		nodes[i].parent = m;
		nodes[i].s.setString(buf);
		nodes[m].childs.push_back(i);
	}
	scanf ("%s",buf);
	HashString sample(buf);
	int res=0;
	int slen = sample.Length();

	queue<pair<int,int> > q;
	q.push (make_pair(1,0));
	while (!q.empty())
	{
		pair<int,int> pa = q.front();
		q.pop();
		int u=pa.first;
		int from=pa.second;
		int ulen = nodes[u].s.Length();
		int len=min(ulen,slen-from);
		if (sample.isEqual(from,nodes[u].s,0,len))
		{
			if (from+len==slen) res++;
			else
			{
				for (i=0;i<nodes[u].childs.size();i++)
				{
					q.push(make_pair(nodes[u].childs[i],from+len));
				}
			}
		}
		if (!from)
		{
			for (i=1;i<ulen;i++)
			{
				len=min(ulen-i,slen);
				if (sample.isEqual(0,nodes[u].s,i,len))
				{
					if (len==slen) res++;
					else
					{
						for (j=0;j<nodes[u].childs.size();j++)
						{
							q.push(make_pair(nodes[u].childs[j],len));
						}
					}
				}
			}
			for (i=0;i<nodes[u].childs.size();i++)
			{
				q.push(make_pair(nodes[u].childs[i],0));
			}
		}
	}

	printf ("%d", res);
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

typedef unsigned int uint;

/**
 * Return prefix function r[i] = max prefix which is suffix
 */
vector<int> prefixFunction (string s)
{
	size_t n = s.size();
	vector<int> r(n,0);
	for (size_t i = 1; i < n ; i++)
	{
		size_t j = r[i-1];
		while (j && s[i]!=s[j]) j = r[j-1];
		if (s[i]==s[j]) j++;
		r[i] = j;
	}

	return r;
}

struct Node
{
	int parent;
	vector<int> childs;
	string s;
	vector<int> pref;
};

Node nodes[100100];
char buf[300100];
int pref[300100];

int main ()
{
//	freopen ("input.txt","rt",stdin);
//	freopen ("output.txt","wt",stdout);
	int i,j,k,m,n;

/*
	printf ("100000\n");
	for (i=2;i<=100000;i++)
	{
		printf ("%d ",i-1);
		for (j=0;j<2;j++) printf ("%c",'a'+rand()%2);
		printf ("\n");
	}
*/
	scanf ("%d",&n);
	nodes[1].s="#";
	nodes[1].pref.assign(1,0);
	for (i=2;i<=n;i++)
	{
		scanf ("%d %s",&m,buf);
		nodes[i].parent = m;
		nodes[i].s=buf;
		nodes[i].pref.assign(nodes[i].s.size(),0);
		nodes[m].childs.push_back(i);
	}
	scanf ("%s",buf);
	string sample(buf);
	sample+="@";
	vector<int> pr = prefixFunction (sample);
	for (i=0;i<pr.size();i++) pref[i]=pr[i];
	int res=0;
	int slen = sample.size();

	queue<int> q;
	q.push (1);
	while (!q.empty())
	{
		int u = q.front();
		q.pop();
		string& a=nodes[u].s;
		for (i=0;i<a.size();i++)
		{
			if (!i)
			{
				if (u==1) j = pref[slen-1];
				else j = nodes[nodes[u].parent].pref[nodes[nodes[u].parent].s.size()-1];
			}
			else j = nodes[u].pref[i-1];
			while (j && a[i]!=sample[j]) j = pref[j-1];
			if (a[i]==sample[j]) j++;
			nodes[u].pref[i] = j;
			if (nodes[u].pref[i] == slen-1) res++;
		}
		for (i=0;i<nodes[u].childs.size();i++)
		{
			q.push(nodes[u].childs[i]);
		}
	}

	printf ("%d", res);
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

typedef unsigned int uint;
const uint base=257;
uint bp[300100];

class HashString
{
	string s;
	vector<uint> hash;
public:
	HashString(){}
	HashString(string _s)
	{
		setString (_s);
	}

	void setString (const string& _s)
	{
		s=_s;
		hash.assign (s.size(),0);
		hash[0]=(uint)s[0];
		for (int i=1;i<s.size();i++)
		{
			hash[i]=hash[i-1]+bp[i]*(uint)s[i];
		}
	}

	int Length() const { return s.size(); }

	bool isEqual (int from_this, const HashString& other, int from_other, int len)
	{
		if (from_this + len > s.size() || from_other+len>other.s.size()) return false;
		if ((hash[from_this+len-1]-(from_this?hash[from_this-1]:0)) * bp[from_other] !=
			(other.hash[from_other+len-1]-(from_other?other.hash[from_other-1]:0)) * bp[from_this])
			return false;
		int i;
		for (i=0;i<len && s[from_this++]==other.s[from_other++];i++);
		return i==len;
	}
};

struct Node
{
	int parent;
	vector<int> childs;
	HashString s;
};

Node nodes[100100];
char buf[300100];

int main ()
{
//	freopen ("input.txt","rt",stdin);
//	freopen ("output.txt","wt",stdout);
	int i,j,k,m,n;
	bp[0]=1;
	for (i=1;i<300100;i++) bp[i]=bp[i-1]*base;

	scanf ("%d",&n);
	nodes[1].s.setString("#");
	for (i=2;i<=n;i++)
	{
		scanf ("%d %s",&m,buf);
		nodes[i].parent = m;
		nodes[i].s.setString(buf);
		nodes[m].childs.push_back(i);
	}
	scanf ("%s",buf);
	HashString sample(buf);
	int res=0;
	int slen = sample.Length();

	queue<pair<int,int> > q;
	q.push (make_pair(1,0));
	while (!q.empty())
	{
		pair<int,int> pa = q.front();
		q.pop();
		int u=pa.first;
		int from=pa.second;
		int ulen = nodes[u].s.Length();
		int len=min(ulen,slen-from);
		if (sample.isEqual(from,nodes[u].s,0,len))
		{
			if (from+len==slen) res++;
			else
			{
				for (i=0;i<nodes[u].childs.size();i++)
				{
					q.push(make_pair(nodes[u].childs[i],from+len));
				}
			}
		}
		if (!from)
		{
			for (i=1;i<ulen;i++)
			{
				len=min(ulen-i,slen);
				if (sample.isEqual(0,nodes[u].s,i,len))
				{
					if (len==slen) res++;
					else
					{
						for (j=0;j<nodes[u].childs.size();j++)
						{
							q.push(make_pair(nodes[u].childs[j],len));
						}
					}
				}
			}
			for (i=0;i<nodes[u].childs.size();i++)
			{
				q.push(make_pair(nodes[u].childs[i],0));
			}
		}
	}

	printf ("%d", res);
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <string>
#include <string.h>
#include <queue>
#include <set>
#include <complex>
#include <iostream>
#include <fstream>
#include <time.h>
using namespace std;
vector<pair<int,string> > b[100000];
int fail[300001];
int ans=0,tl;
string t;
void dfs(int num,int idx)
{
    for(int i=0;i<b[num].size();i++)
    {
        int start=idx;
        string &tmp=b[num][i].second;
        for(int j=0;j<tmp.length();j++)
        {
            while(start!=-1&&t[start]!=tmp[j]) start=fail[start];
            start++;
            if(start==tl)
            {
                ans++;
                start=fail[tl];
            }
        }
        dfs(b[num][i].first,start);
    }
}
int main()
{
    int n;
    cin>>n;
    pair<int,string> a;
    for(int i=1;i<n;i++)
    {
        cin>>a.first>>a.second;
        b[a.first-1].push_back(make_pair(i,a.second));
    }
    cin>>t;
    tl=t.length();
    int j=0;
    fail[0]=-1;
    for(int i=1;i<tl;i++)
    {
        if(t[i]==t[j]) fail[i]=fail[j];
        else
        {
            fail[i]=j;
            while(j!=-1&&t[i]!=t[j]) j=fail[j];
        }
        j++;
    }
    fail[tl]=j;
    dfs(0,0);
    printf("%d\n",ans);
}


#pragma comment (linker, "/STACK:100000000")
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define N 101000
char s[3*N];
int p[3*N], l, r;
vector <int> m[N];
string w[N];
void dfs(int i, int v)
{
    int j;
    for(j=0; j<w[i].size(); v++, r+=v==l, j++)
        for(; v!=-1 && w[i][j]!=s[v]; v=p[v]);
    for(j=0; j<m[i].size(); dfs(m[i][j], v), j++);
}
int main()
{
    int i, j, n;
    for(scanf("%d", &n), i=1; i<n; scanf("%d%s", &j, s), j--, m[j].push_back(i), w[i]=s, i++);
    scanf("%s", s);
    for(p[0]=-1, j=-1, l=0; s[l]; j++, p[l+1]=j, l++)
        for(; j!=-1 && s[l]!=s[j]; j=p[j]);
    s[l]='$';
    dfs(0, 0);
    printf("%d\n", r);
    return 0;
}


#ifdef ONLINE_JUDGE
#include <iostream>
#else
#include <fstream>
#endif
#include<string>
#include<vector>
using namespace std;
#ifndef ONLINE_JUDGE
#pragma comment(linker, "/STACK:268435456")
 ifstream cin ("input.txt");
 ofstream cout ("output.txt");
 #endif

long long answ;
string t;
struct edge
{
	int kuda;
	string how;
};
int pi[400000];
vector<int> tree[100007];
string str[100007];
int count=1;

void dfs(int v)
{
	if (v==1)
	{
	for(int i=1; i<(int)str[v].size(); i++)
	{
		int j = pi[count-1];
		while ((j > 0) && (str[v][i] != t[j]))
		j = pi[j-1];
		if (str[v][i] == t[j])  ++j;
		pi[count] = j;
		if (pi[count]==t.size()) {answ++;}
		count++;
	}
	}
	else
	{
	for(int i=0; i<(int)str[v].size(); i++)
	{
		int j = pi[count-1];
		while ((j > 0) && (str[v][i] != t[j]))
		j = pi[j-1];
		if (str[v][i] == t[j])  ++j;
		pi[count] = j;
		if (pi[count]==t.size()) {answ++;}
		count++;
	}
	}
	for(int i=0; i<(int)tree[v].size(); i++)
	{
		dfs(tree[v][i]);
	}
	for(int i=0; i<(int)str[v].size(); i++)
	{
		count--;
	}
}

int main()
{

 int n;
cin>>n;
pi[0]=0;
for(int i=2; i<=n; i++)
{
	int a;
	string b;
	cin>>a>>b;
	edge tmp;
	//tmp.kuda=a;
	//tmp.how=b;
	//tree[i].push_back(tmp);
	str[i]=b;
	tree[a].push_back(i);
}
cin>>t;
str[1]=t+"#";
dfs(1);
cout<<answ;
#ifndef ONLINE_JUDGE
cin.close();
cout.close();
#endif
return 0;
}


#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <string.h>

using namespace std;

#define pb(x) push_back(x)

#define FILE "io"

const int MAXN = 100001;
const int MAXLEN = 300001;
const int PRIME = 31;

long long p_pow[MAXLEN * 2];

int n;

vector <int> g[MAXN * 2];
string str[MAXN * 2];

long long ans;

string text;
long long text_h;
int text_length;

char s[MAXLEN * 2];
long long s_h[MAXLEN * 2];

void dfs (int v, int len)
{
    for (int i = 0; i < (int) str[v].length (); i++) {
        s[len] = str[v][i];
        s_h[len] = s_h[len - 1] + p_pow[len] * (s[len] - 'a' + 1);

        if (len - text_length + 1 >= 0) {
            long long cur_h = s_h[len];
            if (len - text_length + 1 > 0)
                cur_h -= s_h[len - text_length];

            if (cur_h == text_h * p_pow[len - text_length + 1])
                ans++;
        }

        len++;
    }

    for (int i = 0; i < (int) g[v].size (); i++)
        dfs (g[v][i], len);
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen (FILE".in", "r", stdin);
    freopen (FILE".out", "w", stdout);
    #endif // ONLINE_JUDGE

    p_pow[0] = 1;
    for (int i = 1; i < MAXLEN * 2; i++)
        p_pow[i] = p_pow[i - 1] * PRIME;

    scanf ("%d\n", &n);
    for (int i = 2; i <= n; i++) {
        int u;

        cin >> u >> str[i];
        g[u].pb(i);
    }

    cin >> text;
    for (int i = 0; s[i]; i++)
        text += s[i];

    text_length = text.length ();
    for (int i = 0; i < text_length; i++)
        text_h += p_pow[i] * (text[i] - 'a' + 1);

    dfs (1, 0);

    printf ("%I64d", ans);

    return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <ctime>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <queue>
#include <memory.h>
#include <iostream>
#include <stack>
#include <complex>
#include <list>

using namespace std;

void ASS(bool b)
{
    if (!b)
    {
        ++*(int*)0;
    }
}

#define FOR(i, x) for (int i = 0; i < (int)(x); ++i)
#define CL(x) memset(x, 0, sizeof(x))
#define CLX(x, y) memset(x, y, sizeof(x))

#pragma comment(linker, "/STACK:106777216")

typedef vector<int> vi;

typedef unsigned long long LL;

const int N = 1 << 17;

struct edge {
	int x;
	int next;
	string s;
};

int g[N];

vector<edge> e;
vi p;

int slen, ans;
int dg[N][27];

void dfs(int x, int pos) {
	for (int r = g[x]; r; r = e[r].next) {
		int cur = pos;
		const string& s = e[r].s;
		FOR(i, s.size()) {
			cur = dg[cur][s[i] - 'a'];
			if (cur == slen)
				++ans;
		}
		dfs(e[r].x, cur);
	}
}

int main() {
	e.reserve(N);
	e.push_back(edge());
	int n;
	cin >> n;
	for (int i = 2; i <= n; ++i) {
		int p;
		cin >> p;
		edge ee;
		ee.x = i;
		ee.next = g[p];
		cin >> ee.s;
		g[p] = (int)e.size();
		e.push_back(ee);
	}
	string s;
	cin >> s;

	s += "$";
	p.resize(s.size(), 0);

	slen = (int)s.size();
	for (int i = 1; i < slen; ++i) {
		int j = p[i - 1];
		while (j > 0 && s[i] != s[j])
			j = p[j - 1];
		if (s[i] == s[j])
			++j;
		p[i] = j;
	}
	for (int i = 0; i < slen; ++i)
		FOR(c, 26)
			if (i > 0 && 'a' + c != s[i])
				dg[i][c] = dg[p[i - 1]][c];
			else
				dg[i][c] = i + ('a' + c == s[i]);

	slen--;
	dfs(1, 0);

	cout << ans << endl;

	return 0;
}


#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <utility>
#include <numeric>
#include <fstream>

using namespace std;

#define		ALL(c)	(c).begin(),(c).end()
#define		SZ(c)	int((c).size())
#define		LEN(s)	int((s).length())
#define		FOR(i,n)	for(int i=0;i<(n);++i)
#define		FORD(i,a,b)	for(int i=(a);i<=(b);++i)
#define		FORR(i,a,b)	for(int i=(b);i>=(a);--i)

typedef istringstream iss;
typedef ostringstream oss;
typedef long double ld;
typedef long long i64;
typedef pair<i64,i64> pii;
typedef pair<pii,pii> ppii;

typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

typedef vector<int> vz;
typedef vector<vz> vvz;
typedef vector<vvz> vvvz;

typedef vector<string> vs;

i64 Z[] = {  777777773,  888888883,  555555541,  666666667 };
i64 M[] = { 1000000021, 1000000007, 1000000033, 1000000087 };
i64 ReZ[300100][4];
i64 PwZ[300100][4];

i64 mod(i64 n, i64 M)
{
	return (n%M+M)%M;
}

i64 lpow(i64 a, i64 b, i64 m)
{
	i64 res = 1;
	while (b > 0)
	{
		if (b & 1) res = (res * a) % m;
		a = (a * a) % m;
		b >>= 1;
	}
	return res;
}

i64 rev(i64 a, i64 p) // p - prime
{
	return lpow(a, p-2, p);
}

class HhString
{
public:
	HhString() : m_Len(-1) {}

	HhString(const string & _s) : m_S(_s)
	{
		m_Len = LEN(m_S);
		m_H.assign(m_Len, vi(2, 0));
		if (m_Len > 0)
		{
			FOR(k, 2) m_H[0][k] = mod(m_S[0], M[k]);
			vi ZP(Z, Z+2);
			FORD(i, 1, m_Len-1)
			{
				FOR(k, 2)
				{
					m_H[i][k] = mod(m_H[i-1][k] + ZP[k] * m_S[i], M[k]);
					ZP[k] = ZP[k] * Z[k] % M[k];
				}
			}
		}
	}

	vi Hash(int a, int b) const
	{
		if (a > b || a < 0 || b >= m_Len) return vi();
		vi r = m_H[b];
		if (a > 0)
		{
			FOR(k, 2)
			{
				r[k] -= m_H[a-1][k];
				if (r[k] < 0) r[k] += M[k];
				r[k] = r[k] * ReZ[a][k] % M[k];
			}
		}
		return r;
	}

	int Len() const
	{
		return m_Len;
	}

private:
	string m_S;
	int m_Len;
	vvi m_H;
};

int N;
vvz D;
vz Pr;
vector<HhString> HhS;
int ans;
HhString H;

void rec(int u, int pos)
{
	if (pos > 0)
	{
		FOR(i, SZ(D[u]))
		{
			int v = D[u][i];
			if (HhS[v].Len() >= H.Len() - pos)
			{
				if (H.Hash(pos, H.Len()-1) == HhS[v].Hash(0, H.Len()-pos-1))
					++ans;
				continue;
			}
			if (H.Hash(pos, pos+HhS[v].Len()-1) == HhS[v].Hash(0, HhS[v].Len()-1))
				rec(v, pos+HhS[v].Len());
		}
	}
	else
	{
		FOR(i, SZ(D[u]))
		{
			int v = D[u][i];
			FORD(j, 0, HhS[v].Len()-H.Len())
			{
				if (H.Hash(0, H.Len()-1) == HhS[v].Hash(j, j+H.Len()-1))
					++ans;
			}
			FORD(j, max(HhS[v].Len()-H.Len()+1, 0), HhS[v].Len()-1)
			{
				if (H.Hash(0, HhS[v].Len()-j-1) == HhS[v].Hash(j, HhS[v].Len()-1))
					rec(v, HhS[v].Len()-j);
			}
		}
	}
}

int main()
{
	//freopen("input.txt", "r", stdin);
	FOR(k, 2)
	{
		PwZ[0][k] = ReZ[0][k] = 1;
		PwZ[1][k] = Z[k];
		ReZ[1][k] = rev(Z[k], M[k]);
	}
	FORD(i, 2, 300002) FOR(k, 2)
	{
		PwZ[i][k] = PwZ[i-1][k] * Z[k] % M[k];
		ReZ[i][k] = ReZ[i-1][k] * ReZ[1][k] % M[k];
	}
	cin >> N;
	Pr.resize(N+1);
	D.resize(N+1);
	HhS.resize(N+1);
	Pr[1] = 0;
	string s;
	FORD(i, 2, N)
	{
		cin >> Pr[i] >> s;
		D[Pr[i]].push_back(i);
		HhS[i] = HhString(s);
	}
	cin >> s;
	H = HhString(s);

	ans = 0;
	FORD(i, 1, N)
		rec(i, 0);
	cout << ans << endl;

	return 0;
}


#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <utility>
#include <numeric>
#include <fstream>

using namespace std;

#define		ALL(c)	(c).begin(),(c).end()
#define		SZ(c)	int((c).size())
#define		LEN(s)	int((s).length())
#define		FOR(i,n)	for(int i=0;i<(n);++i)
#define		FORD(i,a,b)	for(int i=(a);i<=(b);++i)
#define		FORR(i,a,b)	for(int i=(b);i>=(a);--i)

typedef istringstream iss;
typedef ostringstream oss;
typedef long double ld;
typedef long long i64;
typedef pair<i64,i64> pii;
typedef pair<pii,pii> ppii;

typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

typedef vector<int> vz;
typedef vector<vz> vvz;
typedef vector<vvz> vvvz;

typedef vector<string> vs;

i64 Z[] = {  777777773,  888888883,  555555541,  666666667 };
i64 M[] = { 1000000021, 1000000007, 1000000033, 1000000087 };
i64 ReZ[300100][4];
i64 PwZ[300100][4];

i64 mod(i64 n, i64 M)
{
	return (n%M+M)%M;
}

i64 lpow(i64 a, i64 b, i64 m)
{
	i64 res = 1;
	while (b > 0)
	{
		if (b & 1) res = (res * a) % m;
		a = (a * a) % m;
		b >>= 1;
	}
	return res;
}

i64 rev(i64 a, i64 p) // p - prime
{
	return lpow(a, p-2, p);
}

class HhString
{
public:
	HhString() : m_Len(0), m_H(NULL) {}

	void FromStr(const string & s)
	{
		m_H = NULL;
		m_Len = LEN(s);
		if (m_Len > 0)
		{
			m_H = new i64[m_Len];
			m_H[0] = s[0];
			FORD(i, 1, m_Len-1)
			{
				m_H[i] = mod(m_H[i-1] + PwZ[i][0] * s[i], M[0]);
			}
		}
	}

	~HhString()
	{
		if (m_H != NULL) delete [] m_H;
	}

	i64 Hash(int a, int b) const
	{
		if (a > b || a < 0 || b >= m_Len) return -1;
		i64 r = m_H[b];
		if (a > 0)
		{
			r -= m_H[a-1];
			if (r < 0) r += M[0];
			r = r * ReZ[a][0] % M[0];
		}
		return r;
	}

	int Len() const
	{
		return m_Len;
	}

private:
	int m_Len;
	i64 * m_H;
};

int N;
vvz D;
vz Pr;
vector<HhString> HhS;
int ans;
HhString H;

void rec(int u, int pos)
{
	if (pos > 0)
	{
		FOR(i, SZ(D[u]))
		{
			int v = D[u][i];
			if (HhS[v].Len() >= H.Len() - pos)
			{
				if (H.Hash(pos, H.Len()-1) == HhS[v].Hash(0, H.Len()-pos-1))
					++ans;
				continue;
			}
			if (H.Hash(pos, pos+HhS[v].Len()-1) == HhS[v].Hash(0, HhS[v].Len()-1))
				rec(v, pos+HhS[v].Len());
		}
	}
	else
	{
		FOR(i, SZ(D[u]))
		{
			int v = D[u][i];
			FORD(j, 0, HhS[v].Len()-H.Len())
			{
				if (H.Hash(0, H.Len()-1) == HhS[v].Hash(j, j+H.Len()-1))
					++ans;
			}
			FORD(j, max(HhS[v].Len()-H.Len()+1, 0), HhS[v].Len()-1)
			{
				if (H.Hash(0, HhS[v].Len()-j-1) == HhS[v].Hash(j, HhS[v].Len()-1))
					rec(v, HhS[v].Len()-j);
			}
		}
	}
}

int main()
{
	//freopen("input.txt", "r", stdin);
	FOR(k, 1)
	{
		PwZ[0][k] = ReZ[0][k] = 1;
		PwZ[1][k] = Z[k];
		ReZ[1][k] = rev(Z[k], M[k]);
	}
	FORD(i, 2, 300002) FOR(k, 1)
	{
		PwZ[i][k] = PwZ[i-1][k] * Z[k] % M[k];
		ReZ[i][k] = ReZ[i-1][k] * ReZ[1][k] % M[k];
	}
	cin >> N;
	Pr.resize(N+1);
	D.resize(N+1);
	HhS.resize(N+1);
	Pr[1] = 0;
	string s;
	FORD(i, 2, N)
	{
		cin >> Pr[i] >> s;
		D[Pr[i]].push_back(i);
		HhS[i].FromStr(s);
	}
	cin >> s;
	H.FromStr(s);

	ans = 0;
	FORD(i, 1, N)
		rec(i, 0);
	cout << ans << endl;

	return 0;
}


#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <utility>
#include <numeric>
#include <fstream>

using namespace std;

#define		ALL(c)	(c).begin(),(c).end()
#define		SZ(c)	int((c).size())
#define		LEN(s)	int((s).length())
#define		FOR(i,n)	for(int i=0;i<(n);++i)
#define		FORD(i,a,b)	for(int i=(a);i<=(b);++i)
#define		FORR(i,a,b)	for(int i=(b);i>=(a);--i)

typedef istringstream iss;
typedef ostringstream oss;
typedef long double ld;
typedef long long i64;
typedef pair<i64,i64> pii;
typedef pair<pii,pii> ppii;

typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

typedef vector<int> vz;
typedef vector<vz> vvz;
typedef vector<vvz> vvvz;

typedef vector<string> vs;

i64 Z[] = {  777777773,  888888883,  555555541,  666666667 };
i64 M[] = { 1000000021, 1000000007, 1000000033, 1000000087 };
i64 ReZ[300100][4];
i64 PwZ[300100][4];

i64 mod(i64 n, i64 M)
{
	return (n%M+M)%M;
}

i64 lpow(i64 a, i64 b, i64 m)
{
	i64 res = 1;
	while (b > 0)
	{
		if (b & 1) res = (res * a) % m;
		a = (a * a) % m;
		b >>= 1;
	}
	return res;
}

i64 rev(i64 a, i64 p) // p - prime
{
	return lpow(a, p-2, p);
}

class HhString
{
public:
	HhString() : m_Len(-1) {}

	HhString(const string & _s) : m_S(_s)
	{
		m_Len = LEN(m_S);
		m_H.assign(m_Len, vi(2, 0));
		if (m_Len > 0)
		{
			FOR(k, 2) m_H[0][k] = mod(m_S[0], M[k]);
			vi ZP(Z, Z+2);
			FORD(i, 1, m_Len-1)
			{
				FOR(k, 2)
				{
					m_H[i][k] = mod(m_H[i-1][k] + ZP[k] * m_S[i], M[k]);
					ZP[k] = ZP[k] * Z[k] % M[k];
				}
			}
		}
	}

	vi Hash(int a, int b) const
	{
		if (a > b || a < 0 || b >= m_Len) return vi();
		vi r = m_H[b];
		if (a > 0)
		{
			FOR(k, 2)
			{
				r[k] -= m_H[a-1][k];
				if (r[k] < 0) r[k] += M[k];
				r[k] = r[k] * ReZ[a][k] % M[k];
			}
		}
		return r;
	}

	int Len() const
	{
		return m_Len;
	}

private:
	string m_S;
	int m_Len;
	vvi m_H;
};

int N;
vvz D;
vz Pr;
vector<HhString> HhS;
int ans;
HhString H;

void rec(int u, int pos)
{
	if (pos > 0)
	{
		FOR(i, SZ(D[u]))
		{
			int v = D[u][i];
			if (HhS[v].Len() >= H.Len() - pos)
			{
				if (H.Hash(pos, H.Len()-1) == HhS[v].Hash(0, H.Len()-pos-1))
					++ans;
				continue;
			}
			if (H.Hash(pos, pos+HhS[v].Len()-1) == HhS[v].Hash(0, HhS[v].Len()-1))
				rec(v, pos+HhS[v].Len());
		}
	}
	else
	{
		FOR(i, SZ(D[u]))
		{
			int v = D[u][i];
			FORD(j, 0, HhS[v].Len()-H.Len())
			{
				if (H.Hash(0, H.Len()-1) == HhS[v].Hash(j, j+H.Len()-1))
					++ans;
			}
			FORD(j, max(HhS[v].Len()-H.Len()+1, 0), HhS[v].Len()-1)
			{
				if (H.Hash(0, HhS[v].Len()-j-1) == HhS[v].Hash(j, HhS[v].Len()-1))
					rec(v, HhS[v].Len()-j);
			}
		}
	}
}

int main()
{
	freopen("input.txt", "r", stdin);
	FOR(k, 2)
	{
		PwZ[0][k] = ReZ[0][k] = 1;
		PwZ[1][k] = Z[k];
		ReZ[1][k] = rev(Z[k], M[k]);
	}
	FORD(i, 2, 300002) FOR(k, 2)
	{
		PwZ[i][k] = PwZ[i-1][k] * Z[k] % M[k];
		ReZ[i][k] = ReZ[i-1][k] * ReZ[1][k] % M[k];
	}
	cin >> N;
	Pr.resize(N+1);
	D.resize(N+1);
	HhS.resize(N+1);
	Pr[1] = 0;
	string s;
	FORD(i, 2, N)
	{
		cin >> Pr[i] >> s;
		D[Pr[i]].push_back(i);
		HhS[i] = HhString(s);
	}
	cin >> s;
	H = HhString(s);

	ans = 0;
	FORD(i, 1, N)
		rec(i, 0);
	cout << ans << endl;

	return 0;
}


#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <utility>
#include <numeric>
#include <fstream>

using namespace std;

#define		ALL(c)	(c).begin(),(c).end()
#define		SZ(c)	int((c).size())
#define		LEN(s)	int((s).length())
#define		FOR(i,n)	for(int i=0;i<(n);++i)
#define		FORD(i,a,b)	for(int i=(a);i<=(b);++i)
#define		FORR(i,a,b)	for(int i=(b);i>=(a);--i)

typedef istringstream iss;
typedef ostringstream oss;
typedef long double ld;
typedef long long i64;
typedef pair<i64,i64> pii;
typedef pair<pii,pii> ppii;

typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

typedef vector<int> vz;
typedef vector<vz> vvz;
typedef vector<vvz> vvvz;

typedef vector<string> vs;

i64 Z[] = {  777777773,  888888883,  555555541,  666666667 };
i64 M[] = { 1000000021, 1000000007, 1000000033, 1000000087 };

i64 mod(i64 n, i64 M)
{
	return (n%M+M)%M;
}

i64 lpow(i64 a, i64 b, i64 m)
{
	i64 res = 1;
	while (b > 0)
	{
		if (b & 1) res = (res * a) % m;
		a = (a * a) % m;
		b >>= 1;
	}
	return res;
}

i64 rev(i64 a, i64 p) // p - prime
{
	return lpow(a, p-2, p);
}

class HhString
{
public:
	HhString() : m_Len(-1) {}

	HhString(const string & _s) : m_S(_s)
	{
		m_Len = LEN(m_S);
		m_H.assign(m_Len, vi(4, 0));
		if (m_Len > 0)
		{
			FOR(k, 4) m_H[0][k] = mod(m_S[0], M[k]);
			vi ZP(Z, Z+4);
			FORD(i, 1, m_Len-1)
			{
				FOR(k, 4)
				{
					m_H[i][k] = mod(m_H[i-1][k] + ZP[k] * m_S[i], M[k]);
					ZP[k] = ZP[k] * Z[k] % M[k];
				}
			}
		}
	}

	vi Hash(int a, int b) const
	{
		if (a > b || a < 0 || b >= m_Len) return vi();
		vi r = m_H[b];
		if (a > 0)
		{
			FOR(k, 4)
			{
				r[k] -= m_H[a-1][k];
				r[k] = mod(r[k] * rev(lpow(Z[k], a, M[k]), M[k]), M[k]);
			}
		}
		return r;
	}

	int Len() const
	{
		return m_Len;
	}

private:
	string m_S;
	int m_Len;
	vvi m_H;
};

int N;
vvz D;
vz Pr;
vector<HhString> HhS;
int ans;
HhString H;

void rec(int u, int pos)
{
	if (pos > 0)
	{
		FOR(i, SZ(D[u]))
		{
			int v = D[u][i];
			if (HhS[v].Len() >= H.Len() - pos)
			{
				if (H.Hash(pos, H.Len()-1) == HhS[v].Hash(0, H.Len()-pos-1))
					++ans;
				continue;
			}
			if (H.Hash(pos, pos+HhS[v].Len()-1) == HhS[v].Hash(0, HhS[v].Len()-1))
				rec(v, pos+HhS[v].Len());
		}
	}
	else
	{
		FOR(i, SZ(D[u]))
		{
			int v = D[u][i];
			FORD(j, 0, HhS[v].Len()-H.Len())
			{
				if (H.Hash(0, H.Len()-1) == HhS[v].Hash(j, j+H.Len()-1))
					++ans;
			}
			FORD(j, max(HhS[v].Len()-H.Len()+1, 0), HhS[v].Len()-1)
			{
				if (H.Hash(0, HhS[v].Len()-j-1) == HhS[v].Hash(j, HhS[v].Len()-1))
					rec(v, HhS[v].Len()-j);
			}
		}
	}
}

int main()
{
	//freopen("input.txt", "r", stdin);
	cin >> N;
	Pr.resize(N+1);
	D.resize(N+1);
	HhS.resize(N+1);
	Pr[1] = 0;
	string s;
	FORD(i, 2, N)
	{
		cin >> Pr[i] >> s;
		D[Pr[i]].push_back(i);
		HhS[i] = HhString(s);
	}
	cin >> s;
	H = HhString(s);

	ans = 0;
	FORD(i, 1, N)
		rec(i, 0);
	cout << ans << endl;

	return 0;
}


#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <utility>
#include <numeric>
#include <fstream>

using namespace std;

#define		ALL(c)	(c).begin(),(c).end()
#define		SZ(c)	int((c).size())
#define		LEN(s)	int((s).length())
#define		FOR(i,n)	for(int i=0;i<(n);++i)
#define		FORD(i,a,b)	for(int i=(a);i<=(b);++i)
#define		FORR(i,a,b)	for(int i=(b);i>=(a);--i)

typedef istringstream iss;
typedef ostringstream oss;
typedef long double ld;
typedef long long i64;
typedef pair<i64,i64> pii;
typedef pair<pii,pii> ppii;

typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

typedef vector<int> vz;
typedef vector<vz> vvz;
typedef vector<vvz> vvvz;

typedef vector<string> vs;

i64 Z[] = {  777777773,  888888883,  555555541,  666666667 };
i64 M[] = { 1000000021, 1000000007, 1000000033, 1000000087 };
i64 ReZ[300100][4];
i64 PwZ[300100][4];

i64 mod(i64 n, i64 M)
{
	return (n%M+M)%M;
}

i64 lpow(i64 a, i64 b, i64 m)
{
	i64 res = 1;
	while (b > 0)
	{
		if (b & 1) res = (res * a) % m;
		a = (a * a) % m;
		b >>= 1;
	}
	return res;
}

i64 rev(i64 a, i64 p) // p - prime
{
	return lpow(a, p-2, p);
}

class HhString
{
public:
	HhString() : m_Len(0), m_H(NULL) {}

	void FromStr(const string & s)
	{
		m_H = NULL;
		m_Len = LEN(s);
		if (m_Len > 0)
		{
			m_H = new i64[m_Len];
			m_H[0] = s[0];
			FORD(i, 1, m_Len-1)
			{
				m_H[i] = mod(m_H[i-1] + PwZ[i][0] * s[i], M[0]);
			}
		}
	}

	~HhString()
	{
		if (m_H != NULL) delete [] m_H;
	}

	i64 Hash(int a, int b) const
	{
		if (a > b || a < 0 || b >= m_Len) return -1;
		i64 r = m_H[b];
		if (a > 0)
		{
			r -= m_H[a-1];
			if (r < 0) r += M[0];
			r = r * ReZ[a][0] % M[0];
		}
		return r;
	}

	int Len() const
	{
		return m_Len;
	}

private:
	int m_Len;
	i64 * m_H;
};

int N;
vvz D;
vz Pr;
HhString HhS[100100];
int ans;
HhString H;

void rec(int u, int pos)
{
	if (pos > 0)
	{
		FOR(i, SZ(D[u]))
		{
			int v = D[u][i];
			if (HhS[u].Len() >= H.Len() - pos)
			{
				if (H.Hash(pos, H.Len()-1) == HhS[u].Hash(0, H.Len()-pos-1))
					++ans;
				continue;
			}
			if (H.Hash(pos, pos+HhS[u].Len()-1) == HhS[u].Hash(0, HhS[u].Len()-1))
				rec(v, pos+HhS[u].Len());
		}
	}
	else
	{
		FOR(i, SZ(D[u]))
		{
			int v = D[u][i];
			int K = HhS[u].Len()-H.Len();
			FORD(j, 0, K)
			{
				if (H.Hash(0, H.Len()-1) == HhS[u].Hash(j, j+H.Len()-1))
					++ans;
			}
			int K1 = max(HhS[u].Len()-H.Len()+1, 0);
			int K2 = HhS[u].Len()-1;
			FORD(j, K1, K2)
			{
				if (H.Hash(0, HhS[u].Len()-j-1) == HhS[u].Hash(j, HhS[u].Len()-1))
					rec(v, HhS[u].Len()-j);
			}
		}
	}
}

int main()
{
	//freopen("input.txt", "r", stdin);
	FOR(k, 1)
	{
		PwZ[0][k] = ReZ[0][k] = 1;
		PwZ[1][k] = Z[k];
		ReZ[1][k] = rev(Z[k], M[k]);
	}
	FORD(i, 2, 300002) FOR(k, 1)
	{
		PwZ[i][k] = PwZ[i-1][k] * Z[k] % M[k];
		ReZ[i][k] = ReZ[i-1][k] * ReZ[1][k] % M[k];
	}
	cin >> N;
	Pr.resize(N+1);
	D.resize(N+1);
	Pr[1] = 0;
	string s;
	FORD(i, 2, N)
	{
		cin >> Pr[i] >> s;
		reverse(ALL(s));
		D[i].push_back(Pr[i]);
		HhS[i].FromStr(s);
	}
	cin >> s;
	reverse(ALL(s));
	H.FromStr(s);

	ans = 0;
	FORD(i, 1, N)
		rec(i, 0);
	cout << ans << endl;

	return 0;
}


#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <utility>
#include <numeric>
#include <fstream>

using namespace std;

#define		ALL(c)	(c).begin(),(c).end()
#define		SZ(c)	int((c).size())
#define		LEN(s)	int((s).length())
#define		FOR(i,n)	for(int i=0;i<(n);++i)
#define		FORD(i,a,b)	for(int i=(a);i<=(b);++i)
#define		FORR(i,a,b)	for(int i=(b);i>=(a);--i)

typedef istringstream iss;
typedef ostringstream oss;
typedef long double ld;
typedef long long i64;
typedef pair<i64,i64> pii;
typedef pair<pii,pii> ppii;

typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

typedef vector<int> vz;
typedef vector<vz> vvz;
typedef vector<vvz> vvvz;

typedef vector<string> vs;

i64 Z[] = {  777777773,  888888883,  555555541,  666666667 };
i64 M[] = { 1000000021, 1000000007, 1000000033, 1000000087 };
i64 ReZ[300100][4];
i64 PwZ[300100][4];

i64 mod(i64 n, i64 M)
{
	return (n%M+M)%M;
}

i64 lpow(i64 a, i64 b, i64 m)
{
	i64 res = 1;
	while (b > 0)
	{
		if (b & 1) res = (res * a) % m;
		a = (a * a) % m;
		b >>= 1;
	}
	return res;
}

i64 rev(i64 a, i64 p) // p - prime
{
	return lpow(a, p-2, p);
}

class HhString
{
public:
	HhString() : m_Len(0), m_H(NULL) {}

	void FromStr(const string & s)
	{
		m_H = NULL;
		m_Len = LEN(s);
		if (m_Len > 0)
		{
			m_H = new i64[m_Len];
			m_H[0] = s[0];
			FORD(i, 1, m_Len-1)
			{
				m_H[i] = mod(m_H[i-1] + PwZ[i][0] * s[i], M[0]);
			}
		}
	}

	~HhString()
	{
		if (m_H != NULL) delete [] m_H;
	}

	i64 Hash(int a, int b) const
	{
		if (a > b || a < 0 || b >= m_Len) return -1;
		i64 r = m_H[b];
		if (a > 0)
		{
			r -= m_H[a-1];
			if (r < 0) r += M[0];
			r = r * ReZ[a][0] % M[0];
		}
		return r;
	}

	int Len() const
	{
		return m_Len;
	}

private:
	int m_Len;
	i64 * m_H;
};

int N;
vvz D;
vz Pr;
HhString HhS[100100];
int ans;
HhString H;

void rec(int u, int pos)
{
	if (pos > 0)
	{
		FOR(i, SZ(D[u]))
		{
			int v = D[u][i];
			if (HhS[v].Len() >= H.Len() - pos)
			{
				if (H.Hash(pos, H.Len()-1) == HhS[v].Hash(0, H.Len()-pos-1))
					++ans;
				continue;
			}
			if (H.Hash(pos, pos+HhS[v].Len()-1) == HhS[v].Hash(0, HhS[v].Len()-1))
				rec(v, pos+HhS[v].Len());
		}
	}
	else
	{
		FOR(i, SZ(D[u]))
		{
			int v = D[u][i];
			int K = HhS[v].Len()-H.Len();
			FORD(j, 0, K)
			{
				if (H.Hash(0, H.Len()-1) == HhS[v].Hash(j, j+H.Len()-1))
					++ans;
			}
			int K1 = max(HhS[v].Len()-H.Len()+1, 0);
			int K2 = HhS[v].Len()-1;
			FORD(j, K1, K2)
			{
				if (H.Hash(0, HhS[v].Len()-j-1) == HhS[v].Hash(j, HhS[v].Len()-1))
					rec(v, HhS[v].Len()-j);
			}
		}
	}
}

int main()
{
	//freopen("input.txt", "r", stdin);
	FOR(k, 1)
	{
		PwZ[0][k] = ReZ[0][k] = 1;
		PwZ[1][k] = Z[k];
		ReZ[1][k] = rev(Z[k], M[k]);
	}
	FORD(i, 2, 300002) FOR(k, 1)
	{
		PwZ[i][k] = PwZ[i-1][k] * Z[k] % M[k];
		ReZ[i][k] = ReZ[i-1][k] * ReZ[1][k] % M[k];
	}
	cin >> N;
	Pr.resize(N+1);
	D.resize(N+1);
	Pr[1] = 0;
	string s;
	FORD(i, 2, N)
	{
		cin >> Pr[i] >> s;
		D[Pr[i]].push_back(i);
		HhS[i].FromStr(s);
	}
	cin >> s;
	H.FromStr(s);

	ans = 0;
	FORD(i, 1, N)
		rec(i, 0);
	cout << ans << endl;

	return 0;
}


#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <utility>
#include <numeric>
#include <fstream>

using namespace std;

#define		ALL(c)	(c).begin(),(c).end()
#define		SZ(c)	int((c).size())
#define		LEN(s)	int((s).length())
#define		FOR(i,n)	for(int i=0;i<(n);++i)
#define		FORD(i,a,b)	for(int i=(a);i<=(b);++i)
#define		FORR(i,a,b)	for(int i=(b);i>=(a);--i)

typedef istringstream iss;
typedef ostringstream oss;
typedef long long i64;

typedef vector<int> vi;
typedef vector<string> vs;

i64 mod(i64 n, i64 M)
{
	return (n%M+M)%M;
}

i64 lpow(i64 a, i64 b, i64 m)
{
	i64 res = 1;
	while (b > 0)
	{
		if (b & 1) res = (res * a) % m;
		a = (a * a) % m;
		b >>= 1;
	}
	return res;
}

i64 rev(i64 a, i64 p) // p - prime
{
	return lpow(a, p-2, p);
}

int main()
{
	//freopen("input.txt", "r", stdin);
	const i64 Z = 777777773;
	const i64 M = 1000000021;
	const i64 RZ = rev(Z, M);
	int N;
	cin >> N;
	vi Pr(N+1, 0);
	vi Ch(N+1, 0);
	vs S(N+1);
	Pr[1] = 0;
	FORD(i, 2, N)
	{
		cin >> Pr[i] >> S[i];
		reverse(ALL(S[i]));
		++Ch[Pr[i]];
	}
	string H;
	cin >> H;
	int LH = LEN(H);
	i64 HHH = 0;
	FOR(i, LH) HHH = (HHH * Z + H[i]) % M;

	vi W(N+1, 0);
	int ans = 0;
	FORD(i, 1, N)
	{
		if (Ch[i] > 0) continue;
		int l1 = 0, u1 = i;
		int l2 = 0, u2 = i;
		i64 hsh = 0, PZ = 1;
		FOR(j, LH)
		{
			hsh = (hsh + S[u2][l2] * PZ) % M;
			if (j == LH-1) break;
			++l2;
			if (l2 == LEN(S[u2]))
			{
				u2 = Pr[u2];
				l2 = 0;
				if (u2 == 1 && j < LH-1)
				{
					hsh = -1;
					break;
				}
			}
			PZ = PZ * Z % M;
		}
		if (hsh == -1) continue;
		if (hsh == HHH) ++ans;
		while (1)
		{
			hsh -= S[u1][l1];
			if (hsh < 0) hsh += M;
			++l1;
			if (l1 == LEN(S[u1]))
			{
				l1 = 0, u1 = Pr[u1];
				if (W[u1]) break;
				W[u1] = 1;
			}
			++l2;
			if (l2 == LEN(S[u2]))
			{
				l2 = 0,	u2 = Pr[u2];
				if (u2 == 1) break;
			}
			hsh = (hsh * RZ + S[u2][l2] * PZ) % M;
			if (hsh == HHH) ++ans;
		}
	}
	cout << ans << endl;

	return 0;
}


#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <utility>
#include <numeric>
#include <fstream>

using namespace std;

#define		ALL(c)	(c).begin(),(c).end()
#define		SZ(c)	int((c).size())
#define		LEN(s)	int((s).length())
#define		FOR(i,n)	for(int i=0;i<(n);++i)
#define		FORD(i,a,b)	for(int i=(a);i<=(b);++i)
#define		FORR(i,a,b)	for(int i=(b);i>=(a);--i)

typedef istringstream iss;
typedef ostringstream oss;
typedef long double ld;
typedef long long i64;
typedef pair<int,int> pii;

typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vvvi> vvvvi;

typedef vector<string> vs;

i64 Z[] = {  777777773,  888888883,  555555541,  666666667 };
i64 MD[] = { 1000000021, 1000000007, 1000000033, 1000000087 };

vi Zpow, Zrev;

int N;
vs S;
vector<int> Pr;
vvi SHashes;
string H;
vi HHash;

i64 lpow(i64 a, i64 b, i64 m)
{
	i64 res = 1;
	while (b > 0)
	{
		if (b & 1) res = (res * a) % m;
		a = (a * a) % m;
		b >>= 1;
	}
	return res;
}

i64 rev(i64 a, i64 p) // p - prime
{
	return lpow(a, p-2, p);
}

void FillHash(const string & s, vi & h)
{
	int n = LEN(s);
	h.resize(n);
	h[0] = s[0];
	FORD(i, 1, n-1)
		h[i] = (h[i-1] + s[i] * Zpow[i]) % MD[0];
}

class ThreadedTree
{
public:
	struct ThreadedNode
	{
		vector<int> child;
		vector<int> parent;
		vector<int> len;
		vector<i64> hash;
		int in_idx, out_idx;
	};

	ThreadedTree(int _N): root_id(0), N(_N), M(1)
	{
		tree.resize(_N);
	}

	void AddLeaf(int node_id, int parent_id, int slen, i64 shash)
	{
		if (node_id == parent_id)
			root_id = node_id;
		else
			tree[parent_id].child.push_back(node_id);
		tree[node_id].parent.push_back(parent_id);
		tree[node_id].len.push_back(slen);
		tree[node_id].hash.push_back(shash);
	}

	void Thread()
	{
		_inoutidx = 0;
		FillInOut(root_id);

		N = SZ(tree);
		for (int k = 0; k < N; ++k)
		{
			++M;
			bool all_linked_to_root = true;
			FOR(i, N)
			{
				int p1_id = tree[i].parent[k];
				int p2_id = tree[p1_id].parent[k];
				if (p2_id != root_id) all_linked_to_root = false;
				tree[i].parent.push_back(p2_id);
				tree[i].len.push_back(tree[i].len[k] + tree[p1_id].len[k]);
				tree[i].hash.push_back((tree[i].hash[k] + tree[p1_id].hash[k] * Zpow[tree[i].len[k]]) % MD[0]);
			}
			if (all_linked_to_root) break;
		}
	}

	i64 Hash(int u, int len) const
	{
		if (tree[u].len[M-1] < len) return -1;
		i64 rhash = 0;
		int u1 = u, rlen = len;
		FORR(i, 0, M-1)
		{
			if (tree[u1].len[i] < rlen)
			{
				rhash = (rhash + tree[u1].hash[i] * Zpow[len-rlen]) % MD[0];
				rlen -= tree[u1].len[i];
				u1 = tree[u1].parent[i];
			}
		}
		if (rlen > 0)
			rhash = (rhash + SHashes[u1][rlen-1] * Zpow[len-rlen]) % MD[0];
		return rhash;
	}

	bool isParent(int node_id, int parent_id) const
	{
		return (tree[parent_id].in_idx < tree[node_id].in_idx && tree[node_id].out_idx < tree[parent_id].out_idx);
	}

	int CommonAnc(int id1, int id2) const
	{
		if (id1 == id2) return id1;
		if (isParent(id1, id2)) return id2;
		if (isParent(id2, id1)) return id1;
		int parent_id = id1;
		FORR(i, 0, M-1)
		{
			if (!isParent(id2, tree[parent_id].parent[i]))
				parent_id = tree[parent_id].parent[i];
		}
		parent_id = tree[parent_id].parent[0];
		return parent_id;
	}

protected:
	void FillInOut(int node_id)
	{
		ThreadedNode & node = tree[node_id];
		node.in_idx = _inoutidx++;
		FOR(i, SZ(node.child)) FillInOut(node.child[i]);
		node.out_idx = _inoutidx++;
	}

private:
	vector<ThreadedNode> tree;
	int root_id;
	int N, M;
	int _inoutidx;
};

int main()
{
	//freopen("input.txt", "r", stdin);

	Zpow.assign(300100, 1);
	Zrev.assign(300100, 1);
	Zpow[1] = Z[0];
	Zrev[1] = rev(Z[0], MD[0]);
	FORD(i, 2, 300000)
	{
		Zpow[i] = Zpow[i-1] * Zpow[1] % MD[0];
		Zrev[i] = Zrev[i-1] * Zrev[1] % MD[0];
	}

	cin >> N;
	ThreadedTree TT(N);
	vi ch(N, 0);
	S.resize(N);
	Pr.assign(N, 0);
	SHashes.assign(N, vi());
	FORD(i, 1, N-1)
	{
		cin >> Pr[i] >> S[i];
		reverse(ALL(S[i]));
		--Pr[i];
		++ch[Pr[i]];
		FillHash(S[i], SHashes[i]);
	}
	cin >> H;
	reverse(ALL(H));
	FillHash(H, HHash);
	S[0] = "";
	SHashes[0].assign(1, 0);

	FOR(i, N)
		TT.AddLeaf(i, Pr[i], LEN(S[i]), SHashes[i].back());
	TT.Thread();

	i64 ans = 0;
	FORD(i, 1, N-1)
	{
		int m = LEN(S[i]) - LEN(H);
		FOR(k, m+1)
		{
			i64 sh = SHashes[i][k+LEN(H)-1];
			if (k > 0)
			{
				sh += MD[0] - SHashes[i][k-1];
				sh = sh * Zrev[k] % MD[0];
			}
			if (HHash.back() == sh)
				++ans;
		}
		FORD(k, max(m+1, 0), LEN(S[i])-1)
		{
			int d = LEN(S[i]) - k;
			i64 sh = SHashes[i].back();
			if (k > 0)
			{
				sh += MD[0] - SHashes[i][k-1];
				sh = sh * Zrev[k] % MD[0];
			}
			if (HHash[d-1] != sh) continue;
			i64 sufhh = (HHash.back() - HHash[d-1] + MD[0]) * Zrev[d] % MD[0];
			i64 tsh = TT.Hash(Pr[i], LEN(H)-d);
			if (sufhh == tsh)
				++ans;
		}
	}

	cout << ans << endl;

	return 0;
}


#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <utility>
#include <numeric>
#include <fstream>

using namespace std;

#define		ALL(c)	(c).begin(),(c).end()
#define		SZ(c)	int((c).size())
#define		LEN(s)	int((s).length())
#define		FOR(i,n)	for(int i=0;i<(n);++i)
#define		FORD(i,a,b)	for(int i=(a);i<=(b);++i)
#define		FORR(i,a,b)	for(int i=(b);i>=(a);--i)

typedef istringstream iss;
typedef ostringstream oss;
typedef long double ld;
typedef long long i64;
typedef pair<i64,i64> pii;
typedef pair<pii,pii> ppii;

typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

typedef vector<int> vz;
typedef vector<vz> vvz;
typedef vector<vvz> vvvz;

typedef vector<string> vs;

i64 Z[] = {  777777773,  888888883,  555555541,  666666667 };
i64 M[] = { 1000000021, 1000000007, 1000000033, 1000000087 };
i64 ReZ[300100][4];
i64 PwZ[300100][4];

i64 mod(i64 n, i64 M)
{
	return (n%M+M)%M;
}

i64 lpow(i64 a, i64 b, i64 m)
{
	i64 res = 1;
	while (b > 0)
	{
		if (b & 1) res = (res * a) % m;
		a = (a * a) % m;
		b >>= 1;
	}
	return res;
}

i64 rev(i64 a, i64 p) // p - prime
{
	return lpow(a, p-2, p);
}

class HhString
{
public:
	HhString() : m_Len(0), m_H(NULL) {}

	void FromStr(const string & s)
	{
		m_H = NULL;
		m_Len = LEN(s);
		if (m_Len > 0)
		{
			m_H = new i64[m_Len];
			m_H[0] = s[0];
			FORD(i, 1, m_Len-1)
			{
				m_H[i] = mod(m_H[i-1] + PwZ[i][0] * s[i], M[0]);
			}
		}
	}

	~HhString()
	{
		if (m_H != NULL) delete [] m_H;
	}

	i64 Hash(int a, int b) const
	{
		if (a > b || a < 0 || b >= m_Len) return -1;
		i64 r = m_H[b];
		if (a > 0)
		{
			r -= m_H[a-1];
			if (r < 0) r += M[0];
			r = r * ReZ[a][0] % M[0];
		}
		return r;
	}

	int Len() const
	{
		return m_Len;
	}

private:
	int m_Len;
	i64 * m_H;
};

int N;
vvz D;
vz Pr;
HhString HhS[100100];
int ans;
HhString H;

void rec(int u, int pos)
{
	if (pos > 0)
	{
		FOR(i, SZ(D[u]))
		{
			int v = D[u][i];
			if (HhS[u].Len() >= H.Len() - pos)
			{
				if (H.Hash(pos, H.Len()-1) == HhS[u].Hash(0, H.Len()-pos-1))
					++ans;
				continue;
			}
			if (H.Hash(pos, pos+HhS[u].Len()-1) == HhS[v].Hash(0, HhS[u].Len()-1))
				rec(v, pos+HhS[u].Len());
		}
	}
	else
	{
		FOR(i, SZ(D[u]))
		{
			int v = D[u][i];
			int K = HhS[u].Len()-H.Len();
			FORD(j, 0, K)
			{
				if (H.Hash(0, H.Len()-1) == HhS[u].Hash(j, j+H.Len()-1))
					++ans;
			}
			int K1 = max(HhS[u].Len()-H.Len()+1, 0);
			int K2 = HhS[u].Len()-1;
			FORD(j, K1, K2)
			{
				if (H.Hash(0, HhS[u].Len()-j-1) == HhS[u].Hash(j, HhS[u].Len()-1))
					rec(v, HhS[u].Len()-j);
			}
		}
	}
}

int main()
{
	//freopen("input.txt", "r", stdin);
	FOR(k, 1)
	{
		PwZ[0][k] = ReZ[0][k] = 1;
		PwZ[1][k] = Z[k];
		ReZ[1][k] = rev(Z[k], M[k]);
	}
	FORD(i, 2, 300002) FOR(k, 1)
	{
		PwZ[i][k] = PwZ[i-1][k] * Z[k] % M[k];
		ReZ[i][k] = ReZ[i-1][k] * ReZ[1][k] % M[k];
	}
	cin >> N;
	Pr.resize(N+1);
	D.resize(N+1);
	Pr[1] = 0;
	string s;
	FORD(i, 2, N)
	{
		cin >> Pr[i] >> s;
		reverse(ALL(s));
		D[i].push_back(Pr[i]);
		HhS[i].FromStr(s);
	}
	cin >> s;
	reverse(ALL(s));
	H.FromStr(s);

	ans = 0;
	FORD(i, 1, N)
		rec(i, 0);
	cout << ans << endl;

	return 0;
}


#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <utility>
#include <numeric>
#include <fstream>

using namespace std;

#define		ALL(c)	(c).begin(),(c).end()
#define		SZ(c)	int((c).size())
#define		LEN(s)	int((s).length())
#define		FOR(i,n)	for(int i=0;i<(n);++i)
#define		FORD(i,a,b)	for(int i=(a);i<=(b);++i)
#define		FORR(i,a,b)	for(int i=(b);i>=(a);--i)

typedef istringstream iss;
typedef ostringstream oss;
typedef long double ld;
typedef long long i64;
typedef pair<i64,i64> pii;
typedef pair<pii,pii> ppii;

typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

typedef vector<int> vz;
typedef vector<vz> vvz;
typedef vector<vvz> vvvz;

typedef vector<string> vs;

i64 Z[] = {  777777773,  888888883,  555555541,  666666667 };
i64 M[] = { 1000000021, 1000000007, 1000000033, 1000000087 };

i64 mod(i64 n, i64 M)
{
	return (n%M+M)%M;
}

i64 lpow(i64 a, i64 b, i64 m)
{
	i64 res = 1;
	while (b > 0)
	{
		if (b & 1) res = (res * a) % m;
		a = (a * a) % m;
		b >>= 1;
	}
	return res;
}

i64 rev(i64 a, i64 p) // p - prime
{
	return lpow(a, p-2, p);
}

class HhString
{
public:
	HhString() : m_Len(-1) {}

	HhString(const string & _s) : m_S(_s)
	{
		m_Len = LEN(m_S);
		m_H.assign(m_Len, vi(2, 0));
		if (m_Len > 0)
		{
			FOR(k, 2) m_H[0][k] = mod(m_S[0], M[k]);
			vi ZP(Z, Z+2);
			FORD(i, 1, m_Len-1)
			{
				FOR(k, 2)
				{
					m_H[i][k] = mod(m_H[i-1][k] + ZP[k] * m_S[i], M[k]);
					ZP[k] = ZP[k] * Z[k] % M[k];
				}
			}
		}
	}

	vi Hash(int a, int b) const
	{
		if (a > b || a < 0 || b >= m_Len) return vi();
		vi r = m_H[b];
		if (a > 0)
		{
			FOR(k, 2)
			{
				r[k] -= m_H[a-1][k];
				r[k] = mod(r[k] * rev(lpow(Z[k], a, M[k]), M[k]), M[k]);
			}
		}
		return r;
	}

	int Len() const
	{
		return m_Len;
	}

private:
	string m_S;
	int m_Len;
	vvi m_H;
};

int N;
vvz D;
vz Pr;
vector<HhString> HhS;
int ans;
HhString H;

void rec(int u, int pos)
{
	if (pos > 0)
	{
		FOR(i, SZ(D[u]))
		{
			int v = D[u][i];
			if (HhS[v].Len() >= H.Len() - pos)
			{
				if (H.Hash(pos, H.Len()-1) == HhS[v].Hash(0, H.Len()-pos-1))
					++ans;
				continue;
			}
			if (H.Hash(pos, pos+HhS[v].Len()-1) == HhS[v].Hash(0, HhS[v].Len()-1))
				rec(v, pos+HhS[v].Len());
		}
	}
	else
	{
		FOR(i, SZ(D[u]))
		{
			int v = D[u][i];
			FORD(j, 0, HhS[v].Len()-H.Len())
			{
				if (H.Hash(0, H.Len()-1) == HhS[v].Hash(j, j+H.Len()-1))
					++ans;
			}
			FORD(j, max(HhS[v].Len()-H.Len()+1, 0), HhS[v].Len()-1)
			{
				if (H.Hash(0, HhS[v].Len()-j-1) == HhS[v].Hash(j, HhS[v].Len()-1))
					rec(v, HhS[v].Len()-j);
			}
		}
	}
}

int main()
{
	//freopen("input.txt", "r", stdin);
	cin >> N;
	Pr.resize(N+1);
	D.resize(N+1);
	HhS.resize(N+1);
	Pr[1] = 0;
	string s;
	FORD(i, 2, N)
	{
		cin >> Pr[i] >> s;
		D[Pr[i]].push_back(i);
		HhS[i] = HhString(s);
	}
	cin >> s;
	H = HhString(s);

	ans = 0;
	FORD(i, 1, N)
		rec(i, 0);
	cout << ans << endl;

	return 0;
}