Game
시간 제한2초메모리 제한1024 MB
n개의 맵마다 자동차 A, B, C 중 하나를 배정한다. x는 모두 가능하고 a는 A, b는 B, c는 C를 쓸 수 없다. m개의 함의 조건 (i,hi,j,hj)을 모두 만족하는 배정을 찾거나 -1을 출력한다.
문제
Asphalt is Little L's favorite game. Different from other amateur players, Little L is good at studying game design while playing games, so he has a unique game strategy.
Little L plans to play games, each game uses a map, and Little L will choose a car to complete the game on this map.
Little L has three racing cars, represented by capital letters , , and . There are four types of maps, represented by lowercase letters , , , and .
Among them, car is not suitable for use on map , car is not suitable for use on map , car is not suitable for use on map , and map is suitable for all cars to participate in.
There aren't many maps available for all racers, only maps at most.
The map of the game can be described by a string composed of lowercase letters. For example: means that little L plans to play games, in which the map type of the and games is , suitable for all racing cars, the and maps are , not suitable for racing cars , and the and games are , not suitable for racing cars , and maps are , not suitable for racing .
Little L has some special requirements for the game. These requirements can be described by the quaternion , which means that if the car with the model is used in the game, then the car with the model should be used in the game.
Can you help little L choose the car to use for each game? If there are multiple schemes, output any one of them.
If there is no solution, output -1.
입력
The first line of input contains two non-negative integers , .
Enter the second line as a string .
The meanings of , , are described in the title, where contains characters, and exactly of them are lowercase letters .
Enter a positive integer in the third line, indicating that there are car rules.
The next lines, each line contains a quaternion , where are integers, and are characters , or , see the title description for the meaning.
출력
Output one line.
Output -1 if there is no solution.
If there is a solution, it contains a string of length containing only capital letters A, B, and C, indicating how the little L arranges the use of the car in this game. If there are multiple sets of solutions, just output any one of them.