Background
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.
Title Description
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 4-tuple
, 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
.
Input Specification
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 Specification
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.
Sample Input 1
Copy
3 1
xcc
1
1 A 2 B
Sample Output 1
Copy
ABA
Explanation for Sample Output 1
Little
plans to play
games, where
map type is
, which is suitable for all cars, and
and
maps are
, which is not suitable for car racing
.
Little
Wish: If
game uses car
, then
game uses car
.
Then arranging cars
,
,
for the
games respectively would satisfy all the conditions.
All conditions are also met and considered correct if the car is assigned
or
for
games in turn.
However, when the car is arranged sequentially as
or
, it is not considered the correct answer because all conditions cannot be met.
Sample Input / Output 2
See attached file for details.
Constraints
Comments
Do it yourself then
Bad wording
skill issue