#Lutece1944. Letter Kingdom
Letter Kingdom
Migrated from Lutece 1944 Letter Kingdom
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
One day, you had a dream. In the dream, you got trapped in the Letter Kingdom. Two soldiers caught you, and brought you to the front of the king.
The king asked you: "Are you a programmer?"
You answered: "Yes."
The king said: Our Letter Kingdom is going to hold the National Day ceremony, now we need to check our traffic network, and I appoint you to be the commander of this event. Our country has cities, numbered by the first uppercase letters, for example the first city named , the second city named , and so on. Due to the lack of money, every city only has one directed road to another city. The army will arrange for soldiers to walk between these cities. The soldiers are numbered from to . I will tell you the initial position of each soldier, and then issue three types of orders:
-
Interval Move: Given two integers and , the soldiers numbered between walk along the only directed road from the current city to another city (we'll call it ).
-
Multiple Move: Given an integer , the soldiers whose number is a multiple of ( mod ) do .
-
Commander Report: Given an integer , please tell me which city the soldier numbered located in.
Since you are a smart person, can you complete this task?
Input
The first line consists of two integers and , which represent the amounts of city and soldier.
The second line is a -length string. The letter in the string represents the directed road's leading city from the city. It's guaranteed that the letter in the string differs from the letter in the alphabet, and the string only consists of uppercase letters.
The third line is a -length string. The letter in the string represents the soldier's initial city. The string also only consists of uppercase letters.
The fourth line consists of an integer , which represent the number of king's orders.
Following lines, the first part of the line is an integer .
If , then input two integers and , which represent the soldiers numbered between do .
If , then input an integer , which represents the soldiers whose number is a multiple of do .
If , then input an integer , you should output where the soldier numbered located in.
Its guaranteed there is at least one order that .
Output
For each order that , output the position of the soldier.
Samples
5 6
DAEEA
AEDCBA
7
1 1 4
2 2
3 4
2 3
1 3 6
2 1
3 6
A
D
Resources
2018 Guangdong Collegiate Programming Contest