Under construction

Still being built. Things may change

String Conversion and Queries 2

Interview

Time limit3sMemory limit512 MB

Summary
Apply character replacement queries to a string, and after each type 2 query print the longest run of one repeated character.
Level

Easy3 of 10

Topics
String, Implementation, Brute force
Solved
No attempts yet

Problem

A string SS consisting of uppercase and lowercase English letters is given. A list AA of nn queries on SS is also given. Each query is one of two types.

  • Type 1, written as 1 i1 i2: Replace every character i1i_1 in SS with the character i2i_2. If SS has no character i1i_1, SS does not change.
  • Type 2, written as 2: Apply all type 1 queries given so far to SS, in order. Let TT be the resulting string. Output the maximum length of a substring of TT made of one repeated character. A substring is a contiguous part of TT.

Process the queries in AA from first to last and output the result of each type 2 query.

Input

The first line contains the string SS and the integer nn, separated by a space.

Each of the next nn lines contains one query, in order from the first to the last. A type 1 query is given as the integer 1 followed by the characters i1i_1 and i2i_2, separated by spaces. A type 2 query is given as the integer 2 alone.

Output

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

Constraints

  • 1≤∣S∣≤3000001 \le |S| \le 300000, where SS consists of uppercase and lowercase English letters.
  • 1≤n≤3000001 \le n \le 300000.
  • AA contains only type 1 and type 2 queries.
  • AA contains at least one type 2 query.
  • ∣S∣×|S| \times (the number of type 2 queries) ≤108\le 10^8.
  • 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
    1
    2
    2