QOJ.ac

QOJ

حد الوقت: 5 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓

#17936. White, Dark, Mint Chocolate

الإحصائيات

Coco wants to decorate one wall of her room by arranging three types of chocolates in a triangle. The specific method is as follows:

  • First, fill the bottom row with chocolates of your choice.
  • For each subsequent row above, determine the type of chocolate for each cell based on the two chocolates directly below it:
    • If the two chocolates are the same type, place a chocolate of that same type. (e.g., place a white chocolate above two white chocolates.)
    • If the two chocolates are different types, place a chocolate of the third type. (e.g., place a dark chocolate above a mint chocolate and a white chocolate.)

Below is an example of a completed chocolate decoration following these rules.

Coco has not yet decided on the design of the bottom row and is considering changing the chocolates one by one. For every change Coco makes, tell her what the chocolate at the very top will be.

Input

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

The next line contains a string of length $N$ representing the types of the $N$ chocolates. White chocolate is given as W, dark chocolate as D, and mint chocolate as M.

The next line contains the number of changes $Q$ that Coco makes. ($1 \le Q \le 500\,000$)

The following $Q$ lines each contain the position $i$ of the chocolate to change and the type of chocolate $c$. ($1 \le i \le N$, $c$ is one of W, D, M) All changes are cumulative.

Output

The first line should output the type of the chocolate at the top in the initial state.

The next $Q$ lines should output the type of the chocolate at the top after each of Coco's changes.

Examples

Input 1

9
WDMMDDWMM
5
1 M
4 D
8 W
7 M
5 M

Output 1

M
D
M
D
W
D

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.