from collections import defaultdict

def solve():
    N = int(input())
    tree = defaultdict(list)
    edge_string = {}
    
    for _ in range(N-1):
        u, v, s = input().split()
        u = int(u)
        v = int(v)
        tree[u].append(v)
        edge_string[(u, v)] = s
    
    slogan = input().strip()
    total = 0
    
    # Perform DFS from root (0)
    stack = [(0, "")]
    while stack:
        node, current_str = stack.pop()
        full_str = current_str
        
        # Check all children
        for child in tree[node]:
            new_str = full_str + edge_string[(node, child)]
            count = new_str.count(slogan)
            total += count
            stack.append((child, new_str))
    
    print(total)

solve()