PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000112. Chiếc váy cưới của Fabby (Fabby and Her Wedding Dress)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Chiếc váy cưới của Fabby (Fabby and Her Wedding Dress)

Fabby and Her Wedding Dress

Source: Toph

Version: Phuoc Hung OJ Extended

Problem Statement

Fabby has a list of NN strings S1,S2,…,SNS_1,S_2,\ldots,S_N, consisting only of lowercase English letters.

For a nonempty pattern string TT, define its beauty as the number of indices ii for which TT is a prefix of SiS_i. Equivalently, ∣Si∣≥∣T∣|S_i|\ge |T| and the first ∣T∣|T| characters of SiS_i are exactly TT. Equal strings at different indices are counted separately.

Process QQ operations in their given order:

  • 1 i j C: replace the jj-th character of SiS_i with the lowercase letter C. String length does not change.
  • 2 T: print the beauty of pattern TT in the list after all earlier updates.

Output the answer to every operation of the second type.

Input

  • The first line contains the integer NN.
  • The next NN lines contain S1,…,SNS_1,\ldots,S_N.
  • The next line contains QQ.
  • The final QQ lines contain operations of the form 1 i j C or 2 T.

All indices are 1-based, and strings contain no whitespace.

Output

For each operation 2 T, print the number of strings having TT as a prefix, one integer per line.

Subtasks

  • Subtask 1 (15 points): 1≤N≤301\le N\le30, 1≤Q≤601\le Q\le60, 1≤∣Si∣,∣T∣≤2⋅1051\le|S_i|,|T|\le2\cdot10^5, ∑i∣Si∣≤500\sum_i|S_i|\le500, and the total length of all query patterns TT is at most 500500; 1≤i≤N1\le i\le N, 1≤j≤∣Si∣1\le j\le|S_i|, and every character is a lowercase English letter.

  • Subtask 2 (15 points): 1≤N,Q≤2 0001\le N,Q\le2\,000, 1≤∣Si∣,∣T∣≤2⋅1051\le|S_i|,|T|\le2\cdot10^5, ∑i∣Si∣≤2 000\sum_i|S_i|\le2\,000, and total query-pattern length is at most 2 0002\,000; indices and alphabet as in Subtask 1.

  • Subtask 3 (30 points): 1≤N,Q≤50 0001\le N,Q\le50\,000, 1≤∣Si∣,∣T∣≤2⋅1051\le|S_i|,|T|\le2\cdot10^5, ∑i∣Si∣≤50 000\sum_i|S_i|\le50\,000, and total query-pattern length is at most 50 00050\,000; indices and alphabet as in Subtask 1.

  • Subtask 4 (40 points): 1≤N,Q≤2⋅1051\le N,Q\le2\cdot10^5, 1≤∣Si∣,∣T∣≤2⋅1051\le|S_i|,|T|\le2\cdot10^5, ∑i∣Si∣≤2⋅105\sum_i|S_i|\le2\cdot10^5, and total query-pattern length is at most 2⋅1052\cdot10^5; indices and alphabet as in Subtask 1.

Examples

Example 1

Input

2
abcd
abde
2
1 2 3 c
2 abc

Output

2

Explanation

After the update both strings are abcd, so both start with abc; the result is 22.