Ingrid is a head of a big railway station and, among other duties, is responsible for routing trains to the right platforms. The station has one entrance, and there are many switches that direct trains to other switches and platforms.
Each switch has one inbound track and two outbound tracks, platforms have one inbound track, and station entrance has one outbound track. Each outbound track is connected to one inbound track and vice versa. Every switch and platform is reachable from station entrance.
Platforms have a rail dead ends and you may assume that trains disappear from the platform immediately after arriving to it.

Each morning Ingrid looks at the timetable and writes switch toggling instruction: when and which switch to toggle. She would like to automate this process to save a lot of time.
The first line contains a single integer (3 \le n \le 51) - the total number of switches and platforms on the station.
The -th of the following lines describes a switch or a platform with an index . Description starts with a character for a platform or for a switch. Next number q_i indicates the number of the switch the inbound track is connected to or if it is connected to station entrance (0 \le q_i < i). Description of the platform also contains a unique lowercase English letter - the platform identifier.
Trains spend exactly one minute to move between two connected switches or a switch and a platform. In the morning, each switch is toggled in a way that a train would pass to the one of the two outbound tracks connected to the switch/platform with the lower number.
Next line of the input contains a single integer (1 \le m \le 1000) - the number of trains in timetable.
Each of the following lines contains integer a_i (0 \le a_i \le 10000, a_i > a_{i-1}) - the time in minutes when a train arrives to the station entrance, and the letter p_i - identifier of the destination platform for this train.
In the first line output integer - the number of commands in the switch toggling instruction. For each command, output two integers s_i and t_i (1 \le s_i \le n, 0 \le t_i \le 10^9) - the number of the switch and the time to toggle it. Assume that the switch is toggled between minutes t_i - 1 and t_i.
Output commands in order of non-increasing time. The number of commands should not exceed .
Example 1
Example 2
Example 3
Below is the time trace for the first example.
