#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 233rd233^{rd} 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 nn cities, numbered by the first nn uppercase letters, for example the first city named AA, the second city named BB, and so on. Due to the lack of money, every city only has one directed road to another city. The army will arrange for mm soldiers to walk between these cities. The soldiers are numbered from 11 to mm. I will tell you the initial position of each soldier, and then issue three types of orders:

  1. Interval Move: Given two integers ll and rr, the soldiers numbered between [l,r][l, r] walk along the only directed road from the current city to another city (we'll call it Moving OperationMoving\ Operation).

  2. Multiple Move: Given an integer xx, the soldiers whose number is a multiple of xx (idid mod x=0x = 0) do Moving OperationMoving\ Operation.

  3. Commander Report: Given an integer pp, please tell me which city the soldier numbered pp located in.

Since you are a smart person, can you complete this task?

Input

The first line consists of two integers nn and mm, which represent the amounts of city and soldier.

The second line is a nn-length string. The ithi^{th} letter in the string represents the directed road's leading city from the ithi^{th} city. It's guaranteed that the ithi^{th} letter in the string differs from the ithi^{th} letter in the alphabet, and the string only consists of uppercase letters.

The third line is a mm-length string. The ithi^{th} letter in the string represents the ithi^{th} soldier's initial city. The string also only consists of uppercase letters.

The fourth line consists of an integer qq, which represent the number of king's orders.

Following qq lines, the first part of the line is an integer opop.

If op=1op = 1, then input two integers ll and rr, which represent the soldiers numbered between [l,r][l,r] do Moving OperationMoving\ Operation.

If op=2op = 2, then input an integer xx, which represents the soldiers whose number is a multiple of xx do Moving OperationMoving\ Operation.

If op=3op = 3, then input an integer pp, you should output where the soldier numbered pp located in.

Its guaranteed there is at least one order that op=3op = 3.

  • 1n261 \leq n \leq 26
  • 1m2000001 \leq m \leq 200000
  • 1q2000001 \leq q \leq 200000

Output

For each order that op=3op = 3, 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