Under construction

Still being built. Things may change

String Conversion and Queries

Interview

Time limit3sMemory limit512 MB

Summary
Apply character replacement queries to a string in order and print the current string for each print query.
Level

Medium5 of 10

Topics
String, Implementation
Solved
No attempts yet

Problem

You are given a string SS of uppercase and lowercase English letters. You are also given a list AA of nn queries on SS. Each query is one of the following two types.

  • 1 i1 i21\ i_1\ i_2: Change every character i1i_1 in SS to the character i2i_2. If SS has no character i1i_1, SS is not changed.
  • 22: Print SS after applying all type 11 queries given so far, in order.

Input

The first line contains the string SS and the integer nn in that order.

Each of the next nn lines contains one query, from the first query to the last. A type 11 query is the integer 11 followed by the characters i1i_1 and i2i_2, separated by a space. A type 22 query is the integer 22 alone.

Output

For each type 22 query, print the result on its own line, in order.

Constraints

  • 1≤1 \le length of S≤100,000S \le 100{,}000
  • SS consists of uppercase and lowercase English letters.
  • 1≤n≤300,0001 \le n \le 300{,}000
  • Every query in AA is of type 11 or type 22.
  • AA contains at least one type 22 query.
  • 1≤1 \le total number of characters printed by type 22 queries ≤107\le 10^7
  • Newline characters are not counted as printed characters.
  • i1i_1 and i2i_2 are uppercase or lowercase English letters.

Examples1

  1. Example 1

    Input
    abac 8
    2
    1 a d
    1 d c
    2
    1 A b
    1 c c
    2
    1 c Z
    
    Expected output
    abac
    cbcc
    cbcc