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;
namespace IO {
const int buffer_size = 1e5 + 5;
char buf[buffer_size], *S, *T;
bool flag_EOF;
inline char read_char() {
  if (S == T) T = (S = buf) + fread(buf, 1, buffer_size, stdin);
  return S != T ? *(S++) : EOF;
}
inline int read_int() {
  int flag = 1;
  char c = read_char();
  while (c < '0' || c > '9') {
    if (c == EOF) {
      flag_EOF = true;
      return 0;
    }
    flag = (c == '-' ? -1 : 1);
    c = read_char();
  }
  int x = 0;
  while (c >= '0' && c <= '9') {
    x = x * 10 + (c ^ 48);
    c = read_char();
  }
  return x * flag;
}
inline void read_string(char *s) {
  char x;
  do {
    x = read_char();
  } while (x < 'a' || x > 'z');
  int len = 0;
  while (x >= 'a' && x <= 'z') {
    s[len++] = x;
    x = read_char();
  }
  s[len] = '\0';
}
char fw[buffer_size];
int pw;
inline void flush() { fwrite(fw, 1, pw, stdout); }
inline void write_char(char x) {
  if (pw == buffer_size) {
    flush();
    pw = 0;
  }
  fw[pw++] = x;
}
char st[13];
int top;
inline void write_int(int x) {
  if (!x) {
    write_char('0');
    return;
  }
  if (x < 0) {
    write_char('-');
    x = -x;
  }
  while (x) {
    st[++top] = x % 10 + '0';
    x /= 10;
  }
  while (top > 0) write_char(st[top--]);
}
inline void write_string(const char *s) {
  for (int i = 0; s[i]; ++i) write_char(s[i]);
}
}  // namespace IO
int tot;
const int max_tot = 3e5 + 5;
int tr[max_tot][26], fail[max_tot];
bool exist[max_tot];
multiset<int> s[max_tot];
inline void insert(const char *t, int &id) {
  int cur = 0;
  for (int i = 0; t[i]; ++i) {
    int v = t[i] - 'a';
    if (!tr[cur][v]) tr[cur][v] = ++tot;
    cur = tr[cur][v];
  }
  exist[cur] = true;
  s[cur].insert(0);
  id = cur;
}
int End[max_tot], Last[max_tot], Next[max_tot], e;
inline void add_edge(int x, int y) {
  End[++e] = y;
  Next[e] = Last[x];
  Last[x] = e;
}
int q[max_tot], head, tail;
inline void build() {
  head = 1, tail = 0;
  for (int i = 0; i < 26; ++i) {
    int v = tr[0][i];
    if (v) {
      add_edge(0, v);
      q[++tail] = v;
    }
  }
  while (head <= tail) {
    int u = q[head++];
    for (int i = 0; i < 26; ++i) {
      int v = tr[u][i];
      if (v) {
        fail[v] = tr[fail[u]][i];
        add_edge(fail[v], v);
        q[++tail] = v;
      } else
        tr[u][i] = tr[fail[u]][i];
    }
  }
}
int sz[max_tot], son[max_tot], fath[max_tot];
void dfs1(int x, int fa) {
  sz[x] = 1;
  son[x] = -1;
  fath[x] = fa;
  int max_sz = 0;
  for (int i = Last[x]; i; i = Next[i]) {
    int y = End[i];
    if (y != fa) {
      dfs1(y, x);
      sz[x] += sz[y];
      if (sz[y] > max_sz) {
        max_sz = sz[y];
        son[x] = y;
      }
    }
  }
}
int top[max_tot], dfn[max_tot], Time, old[max_tot];
void dfs2(int x, int top_now) {
  dfn[x] = ++Time;
  old[Time] = x;
  top[x] = top_now;
  if (son[x] != -1) dfs2(son[x], top_now);
  for (int i = Last[x]; i; i = Next[i]) {
    int y = End[i];
    if (y != fath[x] && y != son[x]) dfs2(y, y);
  }
}
int ans;
namespace SegmentTree {
int val[max_tot << 2];
void build(int p, int l, int r) {
  if (l == r) {
    val[p] = (exist[old[l]] ? 0 : -1);
    return;
  }
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  val[p] = max(val[p << 1], val[p << 1 | 1]);
}
void modify(int p, int l, int r, int k, int v) {
  if (l == r) {
    val[p] = v;
    return;
  }
  int mid = (l + r) >> 1;
  if (k <= mid)
    modify(p << 1, l, mid, k, v);
  else
    modify(p << 1 | 1, mid + 1, r, k, v);
  val[p] = max(val[p << 1], val[p << 1 | 1]);
}
void query(int p, int l, int r, int a, int b) {
  if (a <= l && r <= b) {
    ans = max(ans, val[p]);
    return;
  }
  int mid = (l + r) >> 1;
  if (a <= mid) query(p << 1, l, mid, a, b);
  if (b > mid) query(p << 1 | 1, mid + 1, r, a, b);
}
}  // namespace SegmentTree
inline void query(int x) {
  while (x != -1) {
    SegmentTree::query(1, 1, Time, dfn[top[x]], dfn[x]);
    x = fath[top[x]];
  }
}
const int max_n = 3e5 + 5;
int id[max_n], v[max_n];
const int max_len = 3e5 + 5;
char t[max_len];
int main() {
  int n = IO::read_int(), m = IO::read_int();
  for (int i = 1; i <= n; ++i) {
    IO::read_string(t);
    insert(t, id[i]);
  }
  build();
  dfs1(0, -1);
  dfs2(0, 0);
  SegmentTree::build(1, 1, Time);
  while (m--) {
    int op = IO::read_int();
    if (op == 1) {
      int i = IO::read_int(), x = IO::read_int();
      s[id[i]].erase(s[id[i]].find(v[i]));
      s[id[i]].insert(v[i] = x);
      SegmentTree::modify(1, 1, Time, dfn[id[i]], *(--s[id[i]].end()));
    } else {
      IO::read_string(t);
      int cur = 0;
      ans = -1;
      for (int i = 0; t[i]; ++i) {
        cur = tr[cur][t[i] - 'a'];
        query(cur);
      }
      IO::write_int(ans);
      IO::write_char('\n');
    }
  }
  IO::flush();
  return 0;
}