Game
Time limit2sMemory limit1024 MB
Assign cars A, B, or C to each game so every car-use requirement holds, given at most d maps that suit all cars, or report -1.
- Level
Medium7 of 10
- Topics
- Brute force, Graph
- Solved
- No attempts yet
Problem
Little L plans to play games. Each game uses one map, and Little L chooses a car to finish the game on that map.
Little L has three racing cars, , , and . There are four map types, , , , and . Car is not suitable for map , car is not suitable for map , and car is not suitable for map . Map is suitable for every car.
Maps that suit all racers are scarce. There are at most of them.
The games are described by a string of lowercase letters. For example, xaabxcbc describes 8 games. Games 1 and 5 use map , which suits every car. Games 2 and 3 use map , which is not suitable for car . Games 4 and 7 use map , which is not suitable for car . Games 6 and 8 use map , which is not suitable for car .
Little L has some special requirements. Each requirement is a quadruple , which means that if car is used in game , then car must be used in game .
Can you help Little L choose a car for each game? If several assignments work, print any one of them. If none exists, print -1.
Input
The first line contains two integers and .
The second line contains the string of length . Exactly of its characters are .
The third line contains an integer , the number of requirements.
Each of the next lines contains , , , and , where and are integers and and are each one of , , or .
Output
Print one line. If no valid assignment exists, print -1. Otherwise, print a string of length made only of the capital letters , , and , where the -th character is the car used in game .
Constraints