CF917E Upside Down
Description
As we all know, Eleven has special abilities. Thus, Hopper convinced her to close the gate to the Upside Down World with her mind. Upside down monsters like to move between the worlds, so they are going to attack Hopper and Eleven in order to make them stop. The monsters live in the vines. The vines form a tree with $ n $ vertices, numbered from $ 1 $ through $ n $ . There's a lowercase English letter written in each tunnel (edge).
Upside down is a magical world. There are $ m $ types of monsters in upside down, numbered from $ 1 $ through $ m $ . Each type of monster has a special word that gives them powers. The special word of type $ i $ is $ s_{i} $ . There are $ q $ monsters in upside down. Each one is at a junction (vertex) and is going to some other junction. If monster of type $ k $ goes from junction $ i $ to junction $ j $ , the power it gains is the number of times it sees its special world ( $ s_{k} $ ) consecutively in the tunnels. More formally:
If $ f(i,j) $ is the string we get when we concatenate the letters written in the tunnels on the shortest path from $ i $ to $ j $ , then the power the monster gains is the number of occurrences of $ s_{k} $ in $ f(i,j) $ .
Hopper and Eleven want to get prepared, so for each monster, they want to know the power the monster gains after moving.
Input Format
N/A
Output Format
N/A