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;
using namespace std;
const int maxn = 300000 + 10;
const long long inf = 1e15;
const int apsz = 26;
const long long mod = 998244353;
struct AC {
  vector<vector<int> > ch, g;
  vector<int> val, fail, id, inv, wson, sz, dep, top;
  int tot, dfn, ql, qr, ans, value;
  vector<int> maxv;
  void initSegTree() {
    maxv = vector<int>(dfn * 4 + 6, -1);
    treeBuild(1, dfn, 1);
  }
  void treeBuild(int l, int r, int o) {
    if (l == r) {
      maxv[o] = val[inv[l]];
    } else {
      int mid = l + r >> 1;
      treeBuild(l, mid, o << 1);
      treeBuild(mid + 1, r, o << 1 | 1);
      maxv[o] = max(maxv[o << 1], maxv[o << 1 | 1]);
    }
  }
  void query(int l, int r, int o) {
    if (ql <= l && qr >= r) {
      ans = max(ans, maxv[o]);
    } else {
      int mid = l + r >> 1;
      if (ql <= mid) query(l, mid, o << 1);
      if (qr > mid) query(mid + 1, r, o << 1 | 1);
    }
  }
  int Query(int l, int r) {
    ql = l, qr = r;
    if (ql > qr) swap(ql, qr);
    ans = -1;
    query(1, dfn, 1);
    return ans;
  }
  void update(int l, int r, int o) {
    if (ql <= l && qr >= r) {
      maxv[o] = ans;
    } else {
      int mid = l + r >> 1;
      if (ql <= mid) update(l, mid, o << 1);
      if (qr > mid) update(mid + 1, r, o << 1 | 1);
      maxv[o] = max(maxv[o << 1], maxv[o << 1 | 1]);
    }
  }
  void Update(int p, int v) {
    ans = v;
    ql = qr = p;
    update(1, dfn, 1);
  }
  void init() {
    g.clear(), ch.clear();
    val.clear(), fail.clear();
    tot = 0;
    newnode();
  }
  int newnode() {
    val.push_back(-1);
    ch.push_back(vector<int>(apsz, 0));
    fail.push_back(0);
    g.push_back(vector<int>());
    return tot++;
  }
  int insert(const char* s) {
    int now = 0;
    for (int i = 0; s[i]; ++i) {
      int c = s[i] - 'a';
      int& f = ch[now][c];
      if (!f) {
        f = newnode();
      }
      now = ch[now][c];
    }
    val[now] = 0;
    return now;
  }
  void getFail() {
    queue<int> q;
    for (auto c = (0); c < (apsz); ++c) {
      int u = ch[0][c];
      if (u) q.push(u);
    }
    for (; !q.empty();) {
      int r = q.front();
      q.pop();
      for (auto c = (0); c < (apsz); ++c) {
        int u = ch[r][c];
        if (!u) {
          continue;
        }
        q.push(u);
        int v = fail[r];
        while (v && ch[v][c] == 0) v = fail[v];
        fail[u] = ch[v][c];
      }
    }
    for (auto i = (1); i < (tot); ++i) {
      g[fail[i]].push_back(i);
    }
  }
  void dfs(int u, int d) {
    dep[u] = d;
    sz[u] = 1;
    wson[u] = -1;
    for (auto v : g[u]) {
      assert(v != fail[u]);
      dfs(v, d + 1);
      sz[u] += sz[v];
      if (wson[u] < 0 || sz[wson[u]] < sz[v]) wson[u] = v;
    }
  }
  void dfs2(int u, int t) {
    top[u] = t;
    id[u] = ++dfn;
    inv[id[u]] = u;
    if (wson[u] >= 0) dfs2(wson[u], t);
    for (auto v : g[u]) {
      if (v == fail[u] || v == wson[u]) continue;
      dfs2(v, v);
    }
  }
  void build() {
    inv = vector<int>(tot + 1, -1000);
    sz = vector<int>(tot + 1, 0);
    wson = vector<int>(tot + 1);
    dep = vector<int>(tot + 1);
    id = vector<int>(tot + 1);
    top = vector<int>(tot + 1, 0);
    dfs(0, 0);
    dfs2(0, 0);
    initSegTree();
  }
  void update(int u, int v) { Update(id[u], v); }
  int query(int u) {
    int z = u;
    int ans = -1;
    for (; top[u] != 0;) {
      ans = max(ans, Query(id[top[u]], id[u]));
      u = fail[top[u]];
    }
    ans = max(ans, Query(id[top[u]], id[u]));
    return ans;
  }
  int solve(const char* s) {
    int now, ans;
    ans = now = -1;
    ++now;
    for (int i = 0; s[i]; ++i) {
      int c = s[i] - 'a';
      for (; now && ch[now][c] == 0; now = fail[now])
        ;
      now = ch[now][c];
      ans = max(ans, query(now));
    }
    return ans;
  }
} actree;
int n, m, cnt;
char s[maxn];
vector<multiset<int> > valst;
map<int, int> has;
int pos[maxn], val[maxn];
int main(void) {
  actree.init();
  scanf("%d%d", &n, &m);
  for (auto i = (1); i <= (n); ++i) {
    scanf("%s", s);
    pos[i] = actree.insert(s);
    if (!has.count(pos[i])) {
      has[pos[i]] = cnt++;
      valst.push_back(multiset<int>());
    }
    valst[has[pos[i]]].insert(0);
  }
  actree.getFail();
  actree.build();
  int t, i, x;
  for (auto cas = (0); cas < (m); ++cas) {
    scanf("%d", &(t));
    if (t == 1) {
      scanf("%d", &(i)), scanf("%d", &(x));
      assert(has.count(pos[i]));
      int Id = has[pos[i]];
      assert(valst[Id].find(val[i]) != valst[Id].end());
      valst[Id].erase(valst[Id].find(val[i]));
      valst[Id].insert(val[i] = x);
      actree.update(pos[i], *valst[Id].rbegin());
    } else {
      scanf("%s", s);
      printf("%d\n", actree.solve(s));
    }
  }
  return 0;
}