Under construction

Still being built. Things may change

White, Dark, Mint Chocolate

Time limit1sMemory limit1024 MB

Summary
Given a bottom row of W, D, and M chocolates, report the top chocolate's kind after each single-position change to the bottom row.
Level

Medium7 of 10

Topics
Math, Number theory
Solved
No attempts yet

Problem

Coco wants to decorate one wall of a room with three kinds of chocolate arranged in a triangle. The procedure is as follows.

  • First, fill the bottom row with chocolates of any kinds.
  • For each row above, look at the two chocolates directly below each cell and choose the kind as follows.
    • If the two chocolates are the same kind, place a chocolate of that kind. (Example: above two white chocolates, place a white chocolate.)
    • If the two chocolates are different kinds, place a chocolate of the kind that is neither of them. (Example: above a mint chocolate and a white chocolate, place a dark chocolate.)

The finished decoration is shown below.

Coco has not yet decided the design of the bottom row, so Coco changes one chocolate at a time and considers the result. Each time Coco changes a chocolate, report the kind of chocolate on the top.

Input

The first line contains the number of chocolates NN in the bottom row. (1≤N≤5000001\le N\le 500 000)

The next line contains a string of length NN that gives the kinds of the NN chocolates. White chocolate is W, dark chocolate is D, and mint chocolate is M.

The next line contains the number of changes QQ. (1≤Q≤5000001\le Q\le 500 000)

Each of the next QQ lines contains a position ii of the chocolate to change and the new kind cc. (1≤i≤N1\le i\le N, cc is one of W, D, M) All changes accumulate.

Output

On the first line, print the kind of the top chocolate for the initial state.

On each of the next QQ lines, print the kind of the top chocolate after each change.

Examples1

  1. Example 1

    Input
    9
    WDMMDDWMM
    5
    1 M
    4 D
    8 W
    7 M
    5 M
    
    Expected output
    M
    D
    M
    D
    W
    D