#graph305. 游戏
游戏
The Game
Problem Source
NOI2017
Problem Description
Little L plans to play games, each game using one map, and Little L will choose one car to complete the game on that map.
Little L has three cars, denoted by the uppercase letters , , . There are four kinds of maps, denoted by the lowercase letters , , , .
Among them, car is not suitable for map , car is not suitable for map , car is not suitable for map , while map is suitable for all cars.
Maps suitable for all cars are rare, and there are at most of them.
The games' maps can be described by a string of lowercase letters. For example, means Little L plans games, where the 1st and 5th games are on map (suitable for all cars), the 2nd and 3rd are on map (not suitable for car ), the 4th and 7th are on map (not suitable for car ), and the 6th and 8th are on map (not suitable for car ).
Little L has some special requirements for the games, which can be described by a quadruple , meaning: if car is used in the -th game, then car must be used in the -th game.
Can you help Little L choose a car for each game? If there are multiple valid plans, output any one of them.
If there is no solution, output -1.
Input Format
The first line contains two non-negative integers , .
The second line contains a string .
The meanings of , , are as in the problem description; contains characters, exactly of which are the lowercase letter .
The third line contains a positive integer , the number of car-usage rules.
The next lines each contain a quadruple , where are integers and are characters among , , , as described above.
Output Format
Output one line.
If there is no solution, output -1.
If there is a solution, output a string of length containing only the uppercase letters , representing how Little L arranges the cars for the games. If multiple solutions exist, output any one of them.
Sample Input
3 1
xcc
1
1 A 2 B
Sample Output
ABA
Sample Explanation
Little L plans games; the 1st game is on map (suitable for all cars), and the 2nd and 3rd games are on map (not suitable for car ).
Little L wants: if car is used in the 1st game, then car must be used in the 2nd game.
Then assigning cars to the three games respectively satisfies all conditions.
Assigning or to the three games also satisfies all conditions and is also considered a correct answer.
But assigning or does not satisfy all conditions, so they are not considered correct answers.