P17287 [Algo Beat Contest 013 & MSOI R2] Laugh It Off

Background

![](https://cdn.luogu.com.cn/upload/image_hosting/y1mkztbx.png) *"Whether you gain or lose, just laugh it off."*

Description

You are given $q$ ciphertexts. Each ciphertext consists of lowercase letters and “garbled codes”. There are $26$ kinds of “garbled codes”, which are the $26$ Arabic numerals from $1$ to $26$. The letter corresponding to $1$ is $a$, $2$ corresponds to $b$, and so on. Now you are given an operation value $p$: - When $p$ equals $1$, you need to convert all “garbled codes” in the ciphertext into lowercase letters. Specifically, you should treat each maximal consecutive digit segment as one “garbled code” and translate it into a single letter. - When $p$ equals $2$, you need to convert all lowercase letters in the ciphertext into “garbled codes”.

Input Format

The first line contains an integer $q$, meaning there are $q$ ciphertexts. In the next $q$ lines, each line contains an integer $p$ and a string $s_i$, representing the operation value and the ciphertext, respectively.

Output Format

Output $q$ lines. Each line contains the ciphertext after performing the required operation.

Explanation/Hint

**Constraints** **This problem uses bundled testdata.** ::cute-table{tuack} | Subtask ID | $q \le$ | $\lvert s_i \rvert \le$ | Special Property | Score | | :-: | :-: | :-: | :-: | :-: | | $1$ | $2\times 10^5$ | $10^3$ | $p=1$, and the garbled codes only include $1$ to $9$ | $20$ | | $2$ | ^ | $10^3$ | $p=2$, and the ciphertext only includes lowercase letters | $20$ | | $3$ | ^ | $2\times 10^5$ | The garbled codes only include $1$ to $9$ | $20$ | | $4$ | ^ | $2\times 10^5$ | None | $40$ | For all data, it holds that: - $1 \le q \le 2 \times 10^5$ - $1 \le \lvert s_i \rvert \le 2 \times 10^5$ - $\sum \lvert s_i \rvert \le 2 \times 10^5$ - $p \in \{1,2\}$ - It is guaranteed that the ciphertext contains only lowercase letters and digit characters. - When $p=1$, the number represented by every maximal consecutive digit segment in the ciphertext is within $[1,26]$. Translated by ChatGPT 5