Ingrid runs a large railway station, and one of her duties is routing trains to the right platforms. The station has one entrance and many switches that send trains on to other switches and to platforms.
A switch has one inbound track and two outbound tracks. A platform has one inbound track, and the station entrance has one outbound track. Every outbound track is joined to exactly one inbound track, and every inbound track to exactly one outbound track. Every switch and every platform is reachable from the entrance.
The track at a platform is a dead end, and a train disappears from the platform as soon as it arrives.
Every morning Ingrid reads the timetable and writes a switch toggling instruction that records which switch to toggle and when. Write the program that does this for her.
The first line contains the number of switches and platforms in the station, n (3≤n≤51).
The i-th of the next n lines describes the switch or the platform with number i. The line starts with the character p for a platform or the character s for a switch. Then comes an integer qi, the number of the switch that the inbound track is connected to, or 0 if it is connected to the station entrance (0≤qi<i). A platform line ends with one lowercase English letter, the name of the platform. All platform names are different.
A train needs exactly one minute to move between two connected switches, or between a switch and a platform. The entrance and the first switch are one minute apart as well: a train that is at the entrance at minute a is at the switch connected to the entrance at minute a+1. In the morning every switch is set so that a train passes to the connected switch or platform with the lower number.
The next line contains the number of trains in the timetable, m (1≤m≤1000). Each of the next m lines contains an integer ai and a character pi (0≤ai≤10000, ai>ai−1). Here ai is the minute when the train arrives at the station entrance, and pi is the name of the platform this train must reach.
On the first line print the number of commands in the instruction, c. Each of the next c lines holds one command as two integers si and ti (1≤si≤n, 0≤ti≤109), meaning that switch si is toggled between minute ti−1 and minute ti.
Exactly one instruction is accepted. Follow these rules.
If no command is needed, print only 0 on the first line.