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 ull = unsigned long long;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 998244353;
constexpr int MAX = 1100000;
struct HLD {
  vector<int> sz, in, out, head, par;
  vector<vector<int>> g;
  HLD() {}
  HLD(vector<vector<int>>& _g)
      : g(_g),
        sz(_g.size()),
        in(_g.size()),
        out(_g.size()),
        head(_g.size()),
        par(_g.size()) {}
  void dfs_sz(int cur, int pre) {
    sz[cur] = 1;
    for (int& next : g[cur]) {
      if (next == pre) continue;
      dfs_sz(next, cur);
      par[next] = cur;
      sz[cur] += sz[next];
      if (sz[next] > sz[g[cur][0]]) swap(next, g[cur][0]);
    }
  }
  void dfs_hld(int cur, int pre, int& idx) {
    in[cur] = idx++;
    for (int& next : g[cur]) {
      if (next == pre) continue;
      if (next == g[cur][0])
        head[next] = head[cur];
      else
        head[next] = next;
      dfs_hld(next, cur, idx);
    }
    out[cur] = idx;
  }
  void build() {
    dfs_sz(0, -1);
    int idx = 0;
    dfs_hld(0, -1, idx);
  }
  void build(vector<vector<int>>& _g) {
    g = _g;
    sz.resize(g.size());
    in.resize(g.size());
    out.resize(g.size());
    head.resize(g.size());
    par.resize(g.size());
    dfs_sz(0, -1);
    int idx = 0;
    dfs_hld(0, -1, idx);
  }
  int lca(int u, int v) {
    for (;; v = par[head[v]]) {
      if (in[u] > in[v]) swap(u, v);
      if (head[u] == head[v]) return u;
    }
  }
  vector<pair<int, int>> path_query(int u, int v, bool edge = false) {
    vector<pair<int, int>> ret;
    for (;; v = par[head[v]]) {
      if (in[u] > in[v]) swap(u, v);
      if (head[u] == head[v]) break;
      ret.emplace_back(in[head[v]], in[v] + 1);
    }
    ret.emplace_back(in[u] + edge, in[v] + 1);
    return ret;
  }
};
template <int char_size>
struct TrieNode {
  array<int, char_size> nxt;
  int cnt;
  vector<int> accept;
  TrieNode() : cnt(0) { fill(nxt.begin(), nxt.end(), -1); }
};
template <int char_size>
struct Trie {
  using Node = TrieNode<char_size>;
  vector<Node> nodes;
  int root;
  Trie() : root(0) { nodes.emplace_back(Node()); }
  void add(const vector<int>& str, int id) {
    int node_index = 0;
    for (auto& c : str) {
      if (nodes[node_index].nxt[c] == -1) {
        nodes[node_index].nxt[c] = (int)nodes.size();
        nodes.emplace_back(Node());
      }
      nodes[node_index].cnt += 1;
      node_index = nodes[node_index].nxt[c];
    }
    nodes[node_index].cnt += 1;
    nodes[node_index].accept.emplace_back(id);
  }
  void add(const vector<int>& str) { add(str, nodes[0].cnt); }
  int find(const vector<int>& str) {
    int node_index = 0;
    for (auto& c : str) {
      if (nodes[node_index].nxt[c] == -1) return -1;
      node_index = nodes[node_index].nxt[c];
    }
    return node_index;
  }
  int count() const { return nodes[0].cnt; }
  int size() const { return nodes.size(); }
};
template <int char_size>
struct AhoCorasick : Trie<char_size + 1> {
  using Trie<char_size + 1>::Trie;
  const int FAIL = char_size;
  vector<int> correct;
  void build(bool heavy) {
    correct.resize(this->size());
    for (int i = 0; i < correct.size(); i++)
      correct[i] = (int)this->nodes[i].accept.size();
    queue<int> q;
    for (int i = 0; i <= char_size; i++) {
      if (this->nodes[0].nxt[i] >= 0) {
        this->nodes[this->nodes[0].nxt[i]].nxt[FAIL] = 0;
        q.emplace(this->nodes[0].nxt[i]);
      } else
        this->nodes[0].nxt[i] = 0;
    }
    while (!q.empty()) {
      auto& cur = this->nodes[q.front()];
      int fail = cur.nxt[FAIL];
      correct[q.front()] += correct[fail];
      q.pop();
      for (int i = 0; i < char_size; i++) {
        if (cur.nxt[i] >= 0) {
          this->nodes[cur.nxt[i]].nxt[FAIL] = this->nodes[fail].nxt[i];
          if (heavy) {
            auto& u = this->nodes[cur.nxt[i]].accept;
            auto& v = this->nodes[this->nodes[fail].nxt[i]].accept;
            vector<int> accept;
            accept.reserve(u.size() + v.size());
            set_union(u.begin(), u.end(), v.begin(), v.end(),
                      back_inserter(accept));
            u = accept;
          }
          q.emplace(cur.nxt[i]);
        } else
          cur.nxt[i] = this->nodes[fail].nxt[i];
      }
    }
  }
  vector<int> match(vector<int>& str, bool heavy) {
    vector<int> ret(heavy ? this->size() : 1);
    int cur = 0;
    for (auto& c : str) {
      cur = this->nodes[cur].nxt[c];
      if (heavy)
        for (auto& v : this->nodes[cur].accept) ret[v] += 1;
      else
        ret[0] += correct[cur];
    }
    return ret;
  }
  pair<int, long long> move(int c, int cur = 0) {
    int nxt = this->nodes[cur].nxt[c];
    return {nxt, correct[nxt]};
  }
};
template <typename Monoid, typename F>
struct SegmentTree {
  int sz;
  vector<Monoid> seg;
  const F f;
  const Monoid M;
  SegmentTree(int n, const F f, const Monoid& M) : f(f), M(M) {
    sz = 1;
    while (sz < n) sz *= 2;
    seg.assign(2 * sz, M);
  }
  void set(int k, const Monoid& x) { seg[k + sz] = x; }
  void build() {
    for (int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[k * 2], seg[k * 2 + 1]);
    }
  }
  void update(int k, const Monoid& x) {
    k += sz;
    seg[k] = x;
    while (k /= 2) {
      seg[k] = f(seg[k * 2], seg[k * 2 + 1]);
    }
  }
  Monoid query(int a, int b) {
    if (a >= b) return M;
    Monoid L = M, R = M;
    for (a += sz, b += sz; a < b; a /= 2, b /= 2) {
      if (a & 1) L = f(L, seg[a++]);
      if (b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }
};
template <typename Monoid, typename F>
SegmentTree<Monoid, F> get_segment_tree(int n, const F& f, const Monoid& M) {
  return SegmentTree<Monoid, F>(n, f, M);
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, kkt;
  cin >> n >> kkt;
  AhoCorasick<26> ac;
  auto enc = [](string& s) -> vector<int> {
    vector<int> ret(s.size());
    for (int i = 0; i < s.size(); i++) ret[i] = s[i] - 'a';
    return ret;
  };
  vector<int> idx(n);
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    auto v = enc(s);
    ac.add(v);
    idx[i] = ac.find(v);
  }
  vector<vector<int>> g(ac.size());
  ac.build(false);
  for (int i = 0; i < ac.size(); i++) {
    if (ac.nodes[i].nxt[26] != i) {
      g[i].emplace_back(ac.nodes[i].nxt[26]);
      g[ac.nodes[i].nxt[26]].emplace_back(i);
    }
  }
  HLD hld(g);
  hld.build();
  auto f = [&](long long a, long long b) -> long long { return max(a, b); };
  auto seg = get_segment_tree(ac.size(), f, -1LL);
  for (int i = 0; i < ac.size(); i++)
    if (!ac.nodes[i].accept.empty()) seg.set(hld.in[i], 0);
  seg.build();
  vector<multiset<long long>> vms(ac.size());
  for (int i = 0; i < n; i++) vms[idx[i]].emplace(0);
  vector<long long> sc(n);
  while (kkt--) {
    int jupiro;
    cin >> jupiro;
    if (jupiro == 1) {
      int i;
      long long x;
      cin >> i >> x;
      i -= 1;
      auto& ms = vms[idx[i]];
      ms.erase(ms.find(sc[i]));
      sc[i] = x;
      ms.emplace(x);
      seg.update(hld.in[idx[i]], *ms.rbegin());
    } else {
      string s;
      cin >> s;
      auto v = enc(s);
      int cur = 0;
      long long res = -1;
      for (auto c : v) {
        cur = ac.move(c, cur).first;
        for (auto [l, r] : hld.path_query(0, cur)) {
          chmax(res, seg.query(l, r));
        }
      }
      cout << res << "\n";
    }
  }
}