Problem: For the simplicity, let's say that the "Death Note" is a notebook that kills a person when their name is written in it.

It's easy to kill with it, but it's pretty hard to keep track of people you haven't killed and still plan to. You decided to make a "Death Database Management System" — a computer program that provides the easy access to the database of possible victims. Let me describe its specifications to you.

Let's define a victim entity: a victim has a name (not necessarily unique) that consists only of lowercase Latin letters and an integer suspicion value.

At the start of the program the user enters a list of n victim names into a database, each suspicion value is set to 0.

Then the user makes queries of two types: 

  * 1~i~x — set the suspicion value of the i-th victim to x; 
  * 2~q — given a string q find the maximum suspicion value of a victim whose name is a contiguous substring of q. 



Just to remind you, this program doesn't kill people, it only helps to search for the names to write down in an actual notebook. Thus, the list of the victims in the database doesn't change throughout the queries.

What are you waiting for? Write that program now!

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 3 ⋅ 10^5) — the number of victims and the number of queries, respectively.

Each of the next n lines contains a single string s_i — the name of the i-th victim. Each name consists only of lowercase Latin letters.

Each of the next m lines contains a query of one of two types: 

  * 1~i~x (1 ≤ i ≤ n, 0 ≤ x ≤ 10^9) — change the suspicion value of the i-th victim to x; 
  * 2~q — given a string q consisting only of lowercase Latin letters find the maximum suspicion value of a victim whose name is a contiguous substring of q. 



There is at least one query of the second type. The total length of the strings s_i doesn't exceed 3 ⋅ 10^5. The total length of the strings q doesn't exceed 3 ⋅ 10^5. 

Output

For each query of the second type print an integer value. If there is no victim name that is a contiguous substring of q, then print -1. Otherwise, print the maximum suspicion value of a victim whose name is a contiguous substring of q.

Examples

Input


5 8
kurou
takuo
takeshi
naomi
shingo
2 nakiraomi
2 abanaomicaba
1 3 943
2 takuotakeshishingo
1 5 135832
2 shingotakeshi
1 5 0
2 shingotakeshi


Output


-1
0
943
135832
943


Input


6 15
a
ab
ba
b
a
ba
2 aa
1 4 4
2 bbb
1 2 1
1 2 18
2 b
2 c
1 6 10
2 aba
2 abbbba
1 2 12
2 bbaaab
1 1 11
1 5 5
2 baa


Output


0
4
4
-1
18
18
12
11

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
inline int read() {
  int s = 0, w = 1;
  register char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
  return s * w;
}
int n, m, tot = 1, ch[N][26], book[N], fail[N], P[N], W[N];
char s[N];
int son[N], siz[N], f[N], d[N], nowid, id[N], top[N], c[N], sum[N << 2],
    flag[N << 2];
multiset<int> Q[N];
int head[N], maxE;
struct Edge {
  int nxt, to;
} e[N << 1];
inline void Add(int u, int v) {
  e[++maxE].nxt = head[u];
  head[u] = maxE;
  e[maxE].to = v;
}
inline void Insert(char *s, int len, int id) {
  int x = 1;
  for (register int i = 0; i < len; i++) {
    int p = s[i] - 'a';
    if (!ch[x][p]) ch[x][p] = ++tot;
    x = ch[x][p];
  }
  Q[x].insert(0);
  book[x] = 1, P[id] = x;
}
inline void Get_Fail() {
  queue<int> Q;
  for (register int i = 0; i < 26; i++)
    if (ch[1][i]) Q.push(ch[1][i]);
  for (register int i = 1; i <= tot; i++) fail[i] = 1;
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    for (register int i = 0; i < 26; i++) {
      if (ch[x][i])
        fail[ch[x][i]] = max(1, ch[fail[x]][i]), Q.push(ch[x][i]);
      else
        ch[x][i] = max(1, ch[fail[x]][i]);
    }
  }
  for (register int i = 2; i <= tot; i++) {
    Add(fail[i], i);
  }
}
void DFS1(int x, int fa) {
  siz[x] = 1, f[x] = fa, d[x] = d[fa] + 1;
  for (int i = head[x]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == fa) continue;
    DFS1(v, x);
    siz[x] += siz[v];
    if (siz[v] > siz[son[x]]) son[x] = v;
  }
}
void DFS2(int x, int topf) {
  id[x] = ++nowid, top[x] = topf;
  c[nowid] = (book[x]) ? (0) : (-1);
  if (!son[x]) return;
  DFS2(son[x], topf);
  for (int i = head[x]; i; i = e[i].nxt) {
    int v = e[i].to;
    if ((v ^ son[x]) && (v ^ f[x])) DFS2(v, v);
  }
}
inline void Push_Up(int x) { sum[x] = max(sum[(x << 1)], sum[(x << 1 | 1)]); }
void Build(int x, int l, int r) {
  if (l == r) {
    sum[x] = c[l];
    return;
  }
  int mid = (l + r) / 2;
  Build((x << 1), l, mid), Build((x << 1 | 1), mid + 1, r);
  Push_Up(x);
}
void UpDate(int pos, int l, int r, int x, int w) {
  if (l == r) {
    sum[x] = w;
    return;
  }
  int mid = (l + r) / 2;
  if (pos <= mid)
    UpDate(pos, l, mid, (x << 1), w);
  else
    UpDate(pos, mid + 1, r, (x << 1 | 1), w);
  Push_Up(x);
}
int Ask(int u, int v, int l, int r, int x) {
  if (l >= u && r <= v) return sum[x];
  int mid = (l + r) / 2;
  int gt = -1;
  if (u <= mid) gt = max(gt, Ask(u, v, l, mid, (x << 1)));
  if (v > mid) gt = max(gt, Ask(u, v, mid + 1, r, (x << 1 | 1)));
  return gt;
}
inline int AskR(int x, int y) {
  int gt = -1;
  while (top[x] ^ top[y]) {
    if (d[top[x]] < d[top[y]]) swap(x, y);
    gt = max(gt, Ask(id[top[x]], id[x], 1, tot, 1));
    x = f[top[x]];
  }
  if (d[x] > d[y]) swap(x, y);
  gt = max(gt, Ask(id[x], id[y], 1, tot, 1));
  return gt;
}
signed main() {
  n = read(), m = read();
  for (register int i = 1; i <= n; i++) {
    scanf("%s", s);
    Insert(s, strlen(s), i);
  }
  Get_Fail();
  DFS1(1, 0), DFS2(1, 1);
  Build(1, 1, tot);
  for (register int i = 1; i <= m; i++) {
    int opt;
    opt = read();
    if (opt == 1) {
      int x, y;
      x = read(), y = read();
      Q[P[x]].erase(Q[P[x]].find(W[x]));
      Q[P[x]].insert(y);
      int MX = *Q[P[x]].rbegin();
      UpDate(id[P[x]], 1, tot, 1, MX);
      W[x] = y;
    }
    if (opt == 2) {
      scanf("%s", s);
      int len = strlen(s);
      int ans = -1;
      int x = 1;
      for (register int j = 0; j < len; j++) {
        int p = s[j] - 'a';
        x = ch[x][p];
        x = max(x, 1);
        ans = max(ans, AskR(x, 1));
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}