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 = 3e5 + 10;
struct AC_Automata {
  int root, tree[N][26], tot;
  int fail[N], id[N], vis[N];
  int qu[N], head, tail;
  int newnode() {
    for (int i = 0; i < 26; i++) tree[tot][i] = 0;
    fail[tot] = vis[tot] = 0;
    return tot++;
  }
  void init() {
    tot = 0;
    root = newnode();
  }
  int insert(string s) {
    int cur = root;
    for (int i = 0; s[i]; i++) {
      int tmp = s[i] - 'a';
      if (!tree[cur][tmp]) tree[cur][tmp] = newnode();
      cur = tree[cur][tmp];
    }
    vis[cur] = 1;
    return cur;
  }
  void build() {
    head = 1, tail = 0;
    for (int i = 0; i < 26; i++)
      if (tree[0][i]) qu[++tail] = tree[0][i];
    while (head <= tail) {
      int cur = qu[head++];
      for (int i = 0; i < 26; i++) {
        int tmp = tree[cur][i];
        if (tmp)
          fail[tmp] = tree[fail[cur]][i], qu[++tail] = tmp;
        else
          tree[cur][i] = tree[fail[cur]][i];
      }
    }
    for (int i = 1; i <= tail; i++) vis[qu[i]] |= vis[fail[qu[i]]];
  }
} ac;
struct Segment {
  int a[N];
  struct Tree {
    int l, r, val;
  } tree[N << 2];
  void init(int sz) {
    for (int i = 1; i <= sz; i++) a[i] = 0;
  }
  void build(int pos, int l, int r) {
    tree[pos] = {l, r, a[l]};
    if (l == r) return;
    int mid = l + r >> 1;
    build(pos << 1, l, mid);
    build(pos << 1 | 1, mid + 1, r);
    tree[pos].val = max(tree[pos << 1].val, tree[pos << 1 | 1].val);
  }
  void modify(int pos, int wz, int val) {
    if (tree[pos].l == wz && tree[pos].r == wz) {
      tree[pos].val = val;
      return;
    }
    int mid = tree[pos].l + tree[pos].r >> 1;
    if (wz <= mid) modify(pos << 1, wz, val);
    if (mid < wz) modify(pos << 1 | 1, wz, val);
    tree[pos].val = max(tree[pos << 1].val, tree[pos << 1 | 1].val);
  }
  int query_ma(int pos, int l, int r) {
    if (l <= tree[pos].l && tree[pos].r <= r) return tree[pos].val;
    int mid = tree[pos].l + tree[pos].r >> 1, ma = 0;
    if (l <= mid) ma = max(ma, query_ma(pos << 1, l, r));
    if (mid < r) ma = max(ma, query_ma(pos << 1 | 1, l, r));
    return ma;
  }
} seg;
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  ac.init();
  vector<int> pos(n + 1);
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    pos[i] = ac.insert(s);
  }
  ac.build();
  int sz = ac.tot;
  vector<vector<int>> v(sz);
  for (int i = 1; i < sz; i++) v[ac.fail[i]].emplace_back(i);
  vector<int> deep(sz + 1), siz(sz + 1), fa(sz + 1), son(sz + 1);
  function<void(int, int, int)> dfs1 = [&](int x, int y, int depth) {
    siz[x] = 1;
    deep[x] = depth;
    son[x] = 0;
    for (auto it : v[x]) {
      if (it == y) continue;
      fa[it] = x;
      dfs1(it, x, depth + 1);
      siz[x] += siz[it];
      if ((!son[x]) || siz[it] > siz[son[x]]) son[x] = it;
    }
  };
  dfs1(0, -1, 1);
  int idx = 0;
  vector<int> top(sz + 1), dfn(sz + 1);
  function<void(int, int, int)> dfs2 = [&](int x, int y, int z) {
    top[x] = z;
    dfn[x] = ++idx;
    if (son[x]) dfs2(son[x], x, z);
    for (auto it : v[x]) {
      if (it == y || it == son[x]) continue;
      dfs2(it, x, it);
    }
  };
  dfs2(0, -1, 0);
  seg.init(sz);
  seg.build(1, 1, sz);
  vector<int> pre(n + 1);
  vector<multiset<int>> se(sz + 1);
  for (int i = 1; i <= n; i++) se[dfn[pos[i]]].insert(0);
  while (m--) {
    int op;
    cin >> op;
    if (op == 2) {
      string s;
      cin >> s;
      int cur = 0, ma = 0, ok = 0;
      for (int i = 0; s[i]; i++) {
        cur = ac.tree[cur][s[i] - 'a'];
        auto query = [&](int tmp) {
          int ma = 0;
          while (tmp) {
            ma = max(ma, seg.query_ma(1, dfn[top[tmp]], dfn[tmp]));
            tmp = fa[top[tmp]];
          }
          return ma;
        };
        ma = max(ma, query(cur));
        if (ac.vis[cur]) ok = 1;
      }
      if (!ok)
        cout << -1 << "\n";
      else
        cout << ma << "\n";
    } else {
      int id, x;
      cin >> id >> x;
      int wz = dfn[pos[id]];
      se[wz].erase(se[wz].find(pre[id]));
      se[wz].insert(x);
      pre[id] = x;
      seg.modify(1, wz, *se[wz].rbegin());
    }
  }
  return 0;
}