Under construction

Still being built. Things may change

Game

Time limit2sMemory limit1024 MB

Summary
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 nn 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, AA, BB, and CC. There are four map types, xx, aa, bb, and cc. Car AA is not suitable for map aa, car BB is not suitable for map bb, and car CC is not suitable for map cc. Map xx is suitable for every car.

Maps that suit all racers are scarce. There are at most dd of them.

The games are described by a string of lowercase letters. For example, xaabxcbc describes 8 games. Games 1 and 5 use map xx, which suits every car. Games 2 and 3 use map aa, which is not suitable for car AA. Games 4 and 7 use map bb, which is not suitable for car BB. Games 6 and 8 use map cc, which is not suitable for car CC.

Little L has some special requirements. Each requirement is a quadruple (i,hi,j,hj)(i, h_i, j, h_j), which means that if car hih_i is used in game ii, then car hjh_j must be used in game jj.

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 nn and dd.

The second line contains the string SS of length nn. Exactly dd of its characters are xx.

The third line contains an integer mm, the number of requirements.

Each of the next mm lines contains ii, hih_i, jj, and hjh_j, where ii and jj are integers and hih_i and hjh_j are each one of AA, BB, or CC.

Output

Print one line. If no valid assignment exists, print -1. Otherwise, print a string of length nn made only of the capital letters AA, BB, and CC, where the kk-th character is the car used in game kk.

Constraints

1≤n≤5×1041 \le n \le 5\times 10^4

0≤d≤min⁡(n,8)0 \le d \le \min(n, 8)

1≤m≤1051 \le m \le 10^5

Examples1

  1. Example 1

    Input
    3 1
    xcc
    1
    1 A 2 B
    
    Expected output
    ABA