#graph305. 游戏

游戏

The Game

Problem Source

NOI2017

Problem Description

Little L plans to play nn 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 AA, BB, CC. There are four kinds of maps, denoted by the lowercase letters xx, aa, bb, cc.

Among them, car AA is not suitable for map aa, car BB is not suitable for map bb, car CC is not suitable for map cc, while map xx is suitable for all cars.

Maps suitable for all cars are rare, and there are at most dd of them.

The nn games' maps can be described by a string of lowercase letters. For example, S=xaabxcbcS = \texttt{xaabxcbc} means Little L plans 88 games, where the 1st and 5th games are on map xx (suitable for all cars), the 2nd and 3rd are on map aa (not suitable for car AA), the 4th and 7th are on map bb (not suitable for car BB), and the 6th and 8th are on map cc (not suitable for car CC).

Little L has some special requirements for the games, which can be described by a quadruple (i,hi,j,hj)(i, h_i, j, h_j), meaning: if car hih_i is used in the ii-th game, then car hjh_j must be used in the jj-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 n (1≤n≤5×104)n\ (1 \le n \le 5 \times 10^4), d (0≤d≤8)d\ (0 \le d \le 8).

The second line contains a string SS.

The meanings of nn, dd, SS are as in the problem description; SS contains nn characters, exactly dd of which are the lowercase letter xx.

The third line contains a positive integer m (1≤m≤105)m\ (1 \le m \le 10^5), the number of car-usage rules.

The next mm lines each contain a quadruple i,hi,j,hji, h_i, j, h_j, where i,ji, j are integers and hi,hjh_i, h_j are characters among AA, BB, CC, 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 nn containing only the uppercase letters A,B,CA, B, C, representing how Little L arranges the cars for the nn 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 33 games; the 1st game is on map xx (suitable for all cars), and the 2nd and 3rd games are on map cc (not suitable for car CC).

Little L wants: if car AA is used in the 1st game, then car BB must be used in the 2nd game.

Then assigning cars A,B,AA, B, A to the three games respectively satisfies all conditions.

Assigning BBBBBB or BAABAA to the three games also satisfies all conditions and is also considered a correct answer.

But assigning AABAAB or ABCABC does not satisfy all conditions, so they are not considered correct answers.