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>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
constexpr int N = 3e5 + 9;
constexpr int M = 1e9 + 7;
constexpr int INF = 0x3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcf;
int val[N];
multiset<int> node[N];
int tot;
struct Static {
  int maxi[N << 2];
  void pushUp(int id) { maxi[id] = max(maxi[id << 1], maxi[id << 1 | 1]); }
  void build(int id, int l, int r) {
    if (l == r)
      maxi[id] = 0;
    else {
      int m = (l + r) >> 1;
      build(id << 1, l, m);
      build(id << 1 | 1, m + 1, r);
      pushUp(id);
    }
  }
  void update(int id, int l, int r, int pos, int x) {
    if (l == r) {
      maxi[id] = x;
      return;
    }
    int m = (l + r) >> 1;
    if (pos <= m)
      update(id << 1, l, m, pos, x);
    else
      update(id << 1 | 1, m + 1, r, pos, x);
    pushUp(id);
  }
  int query(int id, int l, int r, int s, int e) {
    if (l == s && e == r) return maxi[id];
    int m = (l + r) >> 1;
    if (e <= m)
      return query(id << 1, l, m, s, e);
    else if (s > m)
      return query(id << 1 | 1, m + 1, r, s, e);
    else
      return max(query(id << 1, l, m, s, m),
                 query(id << 1 | 1, m + 1, r, m + 1, e));
  }
} seg;
struct TreeLink {
  vector<int> g[N];
  int fa[N];
  int sz[N];
  int son[N];
  int sum[N];
  int top[N];
  int dfn[N];
  int tms;
  void addEdge(int u, int v) {
    u++, v++;
    if (u == v) return;
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }
  void dfs(int u, int p) {
    fa[u] = p;
    sum[u] = 1;
    for (int v : g[u]) {
      if (v == fa[u]) continue;
      dfs(v, u);
      if (sum[v] > sum[son[u]]) son[u] = v;
      sum[u] += sum[v];
    }
  }
  void dfs2(int u, int t) {
    top[u] = t;
    dfn[u] = ++tms;
    if (son[u]) dfs2(son[u], t);
    for (int v : g[u]) {
      if (v == fa[u] || v == son[u]) continue;
      dfs2(v, v);
    }
  }
  int query(int u) {
    u++;
    int res = INF2;
    while (u) {
      int t = top[u];
      res = max(res, seg.query(1, 1, tot + 1, dfn[t], dfn[u]));
      u = fa[t];
    }
    return res;
  }
  void update(int u, int x) {
    u++;
    seg.update(1, 1, tot + 1, dfn[u], x);
  }
} tl;
struct AC {
  int ch[N][26];
  int fail[N];
  void clear() {
    for (int i = 0; i <= tot; i++) memset(ch[i], 0, sizeof(ch[i])), fail[i] = 0;
    tot = 0;
  }
  int insert(const char *s) {
    int u = 0;
    for (int i = 1; s[i]; i++) {
      int &v = ch[u][s[i] - 'a'];
      if (!v) v = ++tot;
      u = v;
    }
    return u;
  }
  void build() {
    queue<int> q;
    for (int i = 0; i < 26; i++) {
      if (ch[0][i]) q.emplace(ch[0][i]);
    }
    while (!q.empty()) {
      int u = q.front();
      tl.addEdge(fail[u], u);
      q.pop();
      for (int i = 0; i < 26; i++) {
        if (ch[u][i])
          fail[ch[u][i]] = ch[fail[u]][i], q.emplace(ch[u][i]);
        else
          ch[u][i] = ch[fail[u]][i];
      }
    }
  }
  int run(const char *s) {
    int ans = INF2;
    int u = 0;
    for (int i = 1; s[i]; i++) {
      u = ch[u][s[i] - 'a'];
      ans = max(ans, tl.query(u));
    }
    return ans;
  }
} ac;
int n, m;
char s[N];
int pos[N];
signed main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ;
  memset(val, 0xcf, sizeof(val));
  cin >> n >> m;
  ac.clear();
  for (int i = 1; i <= n; i++) {
    cin >> (s + 1);
    pos[i] = ac.insert(s);
    val[i] = 0;
    node[pos[i]].emplace(0);
  }
  ac.build();
  tl.dfs(1, 0);
  tl.dfs2(1, 1);
  memset(seg.maxi, 0xcf, sizeof(seg.maxi));
  for (int i = 1; i <= n; i++) {
    tl.update(pos[i], 0);
  }
  for (int i = 1; i <= m; i++) {
    int op;
    cin >> op;
    if (op == 1) {
      int id, v;
      cin >> id >> v;
      node[pos[id]].erase(node[pos[id]].find(val[id]));
      val[id] = v;
      node[pos[id]].emplace(v);
      tl.update(pos[id], *node[pos[id]].rbegin());
    } else {
      cin >> (s + 1);
      int ans = ac.run(s);
      if (ans < 0)
        cout << -1 << "\n";
      else
        cout << ans << "\n";
    }
  }
  return 0;
}