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;
struct SegTree {
  int size;
  vector<int> seg;
  SegTree() {}
  SegTree(int size) {
    this->size = size;
    seg.resize(1 << (size + 1));
  }
  void init() {
    for (int i = 0; i < (1 << (size + 1)); i++) seg[i] = -1e9 + 7;
  }
  void update(int i, int val) {
    i += (1 << size);
    seg[i] = val;
    while (i > 1) {
      i /= 2;
      seg[i] = max(seg[i * 2], seg[i * 2 + 1]);
    }
  }
  int query(int a, int b, int k, int l, int r) {
    if (b < l || r < a) return -1e9 + 7;
    if (a <= l && r <= b) return seg[k];
    int lval = query(a, b, k * 2, l, (l + r) / 2);
    int rval = query(a, b, k * 2 + 1, (l + r) / 2 + 1, r);
    return max(lval, rval);
  }
  int query(int a, int b) { return query(a, b, 1, 0, (1 << size) - 1); }
};
struct AhoCorasick {
  struct TrieNode {
    int num, sum;
    int next[26], suff;
    TrieNode() {
      num = sum = 0;
      for (int i = 0; i < 26; i++) next[i] = -1;
    }
  };
  vector<TrieNode> trie;
  AhoCorasick() { init(); }
  void init() {
    trie.clear();
    trie.push_back(TrieNode());
  }
  int seek(string &s) {
    int p = 0;
    for (int i = 0; i < s.size(); i++) {
      int c = s[i] - 'a';
      if (trie[p].next[c] == -1) {
        trie.push_back(TrieNode());
        trie[p].next[c] = (int)trie.size() - 1;
      }
      p = trie[p].next[c];
    }
    return p;
  }
  int trans(int v, int c) {
    if (trie[v].next[c] != -1) return trie[v].next[c];
    if (v == 0) return 0;
    return trans(trie[v].suff, c);
  }
  int addString(string &s) {
    int p = seek(s);
    return p;
  }
  void makeSuffixLink() {
    queue<int> Q;
    Q.push(0);
    trie[0].suff = 0;
    int v;
    while (Q.size()) {
      v = Q.front();
      Q.pop();
      trie[v].sum = trie[v].num + trie[trie[v].suff].sum;
      for (int i = 0; i < 26; i++) {
        int u = trie[v].next[i];
        if (u == -1) continue;
        trie[u].suff = trans(trie[v].suff, i);
        if (v == 0) trie[u].suff = 0;
        Q.push(u);
      }
    }
  }
};
struct HLD {
  int V, logV;
  vector<pair<int, int> > mp;
  map<pair<int, int>, int> mp2;
  vector<pair<int, int> > parent;
  vector<int> pre_order;
  vector<int> back_order;
  int order;
  int global_id, local_id;
  vector<int> size, depth;
  vector<vector<int> > prev;
  HLD() {}
  void predfs(vector<int> G[], int v, int p, int d) {
    size[v] = 1, depth[v] = d, prev[v][0] = p;
    for (int i = 0; i < G[v].size(); i++) {
      if (G[v][i] == p) continue;
      predfs(G, G[v][i], v, d + 1);
      size[v] += size[G[v][i]];
    }
  }
  void maindfs(vector<int> G[], int v, int p) {
    mp[v] = make_pair(global_id, local_id);
    mp2[make_pair(global_id, local_id)] = v;
    pre_order[v] = ++order;
    if (G[v].size() == 1 && G[v][0] == p) {
      back_order[v] = order;
      return;
    }
    vector<pair<int, int> > vec;
    for (int i = 0; i < G[v].size(); i++) {
      if (G[v][i] == p) continue;
      vec.push_back(make_pair(size[G[v][i]], G[v][i]));
    }
    sort(vec.rbegin(), vec.rend());
    local_id++;
    if (vec.size() >= 1) maindfs(G, vec[0].second, v);
    for (int i = 1; i < vec.size(); i++) {
      parent.push_back(mp[v]);
      global_id++, local_id = 0;
      maindfs(G, vec[i].second, v);
    }
    back_order[v] = order;
  }
  int getLCA(int u, int v) {
    int x = u, y = v;
    if (depth[y] > depth[x]) swap(x, y);
    for (int i = logV - 1; i >= 0; i--) {
      if (depth[x] - (1 << i) >= depth[y]) x = prev[x][i];
    }
    if (x == y) return x;
    for (int i = logV - 1; i >= 0; i--) {
      if (prev[x][i] != prev[y][i]) {
        x = prev[x][i];
        y = prev[y][i];
      }
    }
    x = prev[x][0];
    return x;
  }
  void pathcalc(int v, int lca, vector<pair<int, pair<int, int> > > &dest) {
    int gid = mp[v].first, lid = mp[v].second;
    int Gid = mp[lca].first, Lid = mp[lca].second;
    while (Gid != gid) {
      dest.push_back(make_pair(gid, make_pair(0, lid)));
      int ngid = parent[gid].first, nlid = parent[gid].second;
      gid = ngid, lid = nlid;
    }
    dest.push_back(make_pair(gid, make_pair(Lid, lid)));
  }
  void init(vector<int> G[], int V) {
    this->V = V, logV = 0;
    for (int t = V; t; t /= 2) logV++;
    prev.resize(V + 1);
    for (int i = 0; i <= V; i++) prev[i].resize(logV);
    size.resize(V + 1), depth.resize(V + 1);
    predfs(G, 1, 0, 0);
    prev[0][0] = 0;
    for (int i = 1; i < logV; i++) {
      for (int j = 1; j <= V; j++) {
        prev[j][i] = prev[prev[j][i - 1]][i - 1];
      }
    }
    mp.resize(V + 1), mp2.clear();
    parent.clear(), parent.push_back(make_pair(-1, -1));
    pre_order.resize(V + 1), back_order.resize(V + 1);
    global_id = local_id = 0, order = 0;
    maindfs(G, 1, 0);
  }
  void path(int u, int v, vector<pair<int, pair<int, int> > > &dest) {
    dest.clear();
    int lca = getLCA(u, v);
    pathcalc(u, lca, dest);
    pathcalc(v, lca, dest);
    pair<int, pair<int, int> > p =
        make_pair(mp[lca].first, make_pair(mp[lca].second, mp[lca].second));
    for (int i = 0; i < dest.size(); i++) {
      if (dest[i] == p) {
        dest.erase(dest.begin() + i);
        return;
      }
    }
  }
  void getPath(int u, int v, vector<pair<int, int> > &dest) {
    vector<pair<int, pair<int, int> > > src;
    path(u, v, src);
    dest.clear();
    for (int i = 0; i < src.size(); i++) {
      int u = mp2[make_pair(src[i].first, src[i].second.first)],
          v = mp2[make_pair(src[i].first, src[i].second.second)];
      dest.push_back(make_pair(pre_order[u], pre_order[v]));
    }
  }
};
int n, m;
int p[300005];
AhoCorasick aho;
vector<int> G[2000005];
HLD hld;
SegTree seg(20);
int a[300005];
string str[300005];
multiset<int> S[300005];
int sid[300005];
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> str[i];
    p[i] = aho.addString(str[i]) + 1;
  }
  aho.makeSuffixLink();
  map<string, int> mp;
  for (int i = 1; i <= n; i++) mp[str[i]];
  int id = 1;
  for (auto &x : mp) x.second = id++;
  for (int i = 1; i <= n; i++) {
    sid[i] = mp[str[i]];
    S[sid[i]].insert(0);
  }
  for (int i = 1; i < aho.trie.size(); i++) {
    G[aho.trie[i].suff + 1].push_back(i + 1);
  }
  hld.init(G, (int)aho.trie.size());
  seg.init();
  vector<pair<int, int> > res;
  for (int i = 1; i <= n; i++) {
    hld.getPath(p[i], p[i], res);
    seg.update(res[0].first, 0);
  }
  int t, x, y;
  string s;
  for (int(q) = (1); (q) <= (m); (q)++) {
    cin >> t;
    if (t == 1) {
      cin >> x >> y;
      multiset<int> &cset = S[sid[x]];
      cset.erase(cset.lower_bound(a[x]));
      a[x] = y;
      cset.insert(a[x]);
      hld.getPath(p[x], p[x], res);
      seg.update(res[0].first, *cset.rbegin());
    } else {
      cin >> s;
      int ans = -1, v = 0;
      for (int i = 0; i < s.size(); i++) {
        v = aho.trans(v, s[i] - 'a');
        hld.getPath(v + 1, 1, res);
        for (int j = 0; j < res.size(); j++) {
          ans = max(ans, seg.query(res[j].first, res[j].second));
        }
      }
      cout << ans << "\n";
    }
  }
  flush(cout);
  return 0;
}