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;
template <class T>
bool chmin(T &a, const T &b) {
  if (a <= b) return false;
  a = b;
  return true;
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a >= b) return false;
  a = b;
  return true;
}
template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << ',' << p.second;
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (const T &e : v) os << e << " ";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const deque<T> &d) {
  for (const T &e : d) os << e << " ";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &s) {
  os << "{ ";
  for (const T &e : s) os << e << " ";
  os << "}";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const multiset<T> &s) {
  os << "{ ";
  for (const T &e : s) os << e << " ";
  os << "}";
  return os;
}
template <class T, class U>
ostream &operator<<(ostream &os, const map<T, U> &m) {
  os << "{ ";
  for (const auto &[key, val] : m) os << "( " << key << " -> " << val << " ) ";
  os << "}";
  return os;
}
void dump_str_rec(ostringstream &) {}
template <class Head, class... Tail>
void dump_str_rec(ostringstream &oss, Head &&head, Tail &&...tail) {
  oss << ", " << head;
  dump_str_rec(oss, forward<Tail>(tail)...);
}
template <class T, class... U>
string dump_str(T &&arg, U &&...args) {
  ostringstream oss;
  oss << arg;
  dump_str_rec(oss, forward<T>(args)...);
  return oss.str();
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}
struct AhoCorasick {
  const static int alphabet_size = 26;
  const int root = 0;
  const char base = 'a';
  AhoCorasick() : T(1) {}
  AhoCorasick(const vector<string> &ss) : T(1) {
    for (const string &s : ss) add_string(s);
    build();
  }
  struct Node {
    vector<int> child;
    bool leaf;
    int par;
    char par_c;
    int suf_link;
    int exit_link;
    vector<int> go;
    int match_count;
    Node(int par = -1, char par_c = '$')
        : leaf(false),
          par(par),
          par_c(par_c),
          suf_link(-1),
          exit_link(-1),
          match_count(-1) {
      child.assign(alphabet_size, -1);
      go.assign(alphabet_size, -1);
    }
  };
  vector<Node> T;
  int add_string(const string &s) {
    int v = root;
    for (char ch : s) {
      int c = ch - base;
      if (T[v].child[c] == -1) {
        T[v].child[c] = T.size();
        T.emplace_back(v, ch);
      }
      v = T[v].child[c];
    }
    T[v].leaf = true;
    return v;
  }
  int suf_link(int v) {
    if (T[v].suf_link == -1) {
      if (v == root || T[v].par == root) {
        T[v].suf_link = root;
      } else {
        int par_suf_link = suf_link(T[v].par);
        T[v].suf_link = go(par_suf_link, T[v].par_c);
      }
    }
    return T[v].suf_link;
  }
  int go(int v, char ch) {
    int c = ch - base;
    if (T[v].go[c] == -1) {
      if (T[v].child[c] != -1)
        T[v].go[c] = T[v].child[c];
      else
        T[v].go[c] = (v == root) ? root : go(suf_link(v), ch);
    }
    return T[v].go[c];
  }
  int match_count(int v) {
    if (T[v].match_count == -1) {
      if (v == root)
        T[v].match_count = 0;
      else {
        T[v].match_count = match_count(suf_link(v)) + (T[v].leaf ? 1 : 0);
      }
    }
    return T[v].match_count;
  }
  int exit_link(int v) {
    if (T[v].exit_link == -1) {
      if (v == root)
        T[v].exit_link = 0;
      else {
        int suf = suf_link(v);
        T[v].exit_link = T[suf].leaf ? suf : exit_link(suf);
      }
    }
    return T[v].exit_link;
  }
  void build() {
    for (int v = 0; v < T.size(); v++) {
      suf_link(v);
      match_count(v);
      exit_link(v);
      for (int i = 0; i < alphabet_size; i++) go(v, base + i);
    }
  }
  Node &operator[](int v) { return T[v]; }
  int size() const { return T.size(); }
};
template <class D>
struct SegmentTree {
  using DMerger = function<D(D, D)>;
  int length;
  vector<D> seg;
  const DMerger dm;
  const D d_unit;
  SegmentTree() {}
  SegmentTree(int n, const DMerger dm, const D &d_unit)
      : dm(dm), d_unit(d_unit) {
    length = 1;
    while (length < n) length <<= 1;
    seg.assign(2 * length, d_unit);
  }
  SegmentTree(vector<D> vec, const DMerger dm, const D &d_unit)
      : dm(dm), d_unit(d_unit) {
    length = 1;
    while (length < vec.size()) length <<= 1;
    seg.assign(2 * length, d_unit);
    for (int i = 0; i < vec.size(); i++) seg[length - 1 + i] = vec[i];
    for (int i = length - 2; i >= 0; i--)
      seg[i] = dm(seg[i * 2 + 1], seg[i * 2 + 2]);
  }
  void update(int k, D x) {
    k += length - 1;
    seg[k] = x;
    while (k) {
      k = (k - 1) / 2;
      seg[k] = dm(seg[k * 2 + 1], seg[k * 2 + 2]);
    }
  }
  D query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) {
      return d_unit;
    } else if (a <= l && r <= b) {
      return seg[k];
    } else {
      D lch = query(a, b, k * 2 + 1, l, (l + r) / 2);
      D rch = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return dm(lch, rch);
    }
  }
  D query(int a, int b) { return query(a, b, 0, 0, length); }
  D get_point(int x) { return seg[length - 1 + x]; }
};
struct HeavyLightDecomposition {
  vector<vector<int>> g;
  int N, root;
  vector<int> par;
  vector<int> depth, chnum;
  vector<int> top;
  vector<int> head;
  vector<int> heavy;
  vector<int> toseg;
  vector<int> chain_len;
  HeavyLightDecomposition(int N) {
    g.resize(N);
    par.resize(N);
    depth.resize(N);
    chnum.resize(N);
    head.resize(N);
    heavy.resize(N);
    toseg.resize(N);
    chain_len.resize(N);
  }
  void add_edge(int a, int b) {
    g[a].push_back(b);
    g[b].push_back(a);
  }
  struct state {
    int v, p, d;
    bool go;
    state(int v, int p, int d, bool go) : v(v), p(p), d(d), go(go) {}
    state(int v, int p, bool go) : v(v), p(p), go(go) {}
  };
  void init() {
    dfs();
    decompose();
    construct_toseg();
  }
  void dfs() {
    stack<state> st;
    st.push(state(0, -1, 0, true));
    while (!st.empty()) {
      state now = st.top();
      st.pop();
      int v = now.v, p = now.p, d = now.d;
      if (now.go) {
        depth[v] = d;
        par[v] = p;
        st.push(state(v, p, d, false));
        for (int i = 0; i < g[v].size(); i++) {
          if (g[v][i] == p) continue;
          st.push(state(g[v][i], v, d + 1, true));
        }
      } else {
        chnum[v] = 1;
        for (int i = 0; i < g[v].size(); i++) {
          chnum[v] += chnum[g[v][i]];
        }
      }
    }
    return;
  }
  void decompose() {
    stack<state> st;
    st.push(state(0, -1, true));
    while (!st.empty()) {
      state now = st.top();
      st.pop();
      int v = now.v, p = now.p, istop = now.go;
      if (istop) top.push_back(v);
      int hev = -1;
      int val = -1;
      for (int i = 0; i < g[v].size(); i++) {
        if (g[v][i] == p) continue;
        if (val < chnum[g[v][i]]) {
          val = chnum[g[v][i]];
          hev = g[v][i];
        }
      }
      heavy[v] = hev;
      for (int i = 0; i < g[v].size(); i++) {
        if (g[v][i] == p) continue;
        if (g[v][i] == hev)
          st.push(state(g[v][i], v, false));
        else
          st.push(state(g[v][i], v, true));
      }
    }
  }
  void construct_toseg() {
    int id = 0;
    for (int i = 0; i < top.size(); i++) {
      int now = top[i];
      while (1) {
        if (now == -1) break;
        toseg[now] = id++;
        head[now] = top[i];
        now = heavy[now];
        chain_len[top[i]]++;
      }
    }
  }
  int lca(int u, int v) {
    while (head[u] != head[v]) {
      if (depth[head[u]] < depth[head[v]]) swap(u, v);
      u = par[head[u]];
    }
    return (depth[u] < depth[v]) ? u : v;
  }
  template <class Seg>
  void update(Seg &seg, int v, int x) {
    seg.update(toseg[v], x);
  }
  template <class Seg>
  int solve(Seg &seg, int v) {
    int ret = seg.get_point(toseg[v]);
    int now = v;
    while (now != -1) {
      ret = std::max(ret, seg.query(toseg[head[now]], toseg[now] + 1));
      now = par[head[now]];
    }
    return ret;
  }
};
void solve() {
  int n, m;
  cin >> n >> m;
  vector<string> ss(n);
  cin >> ss;
  AhoCorasick ac;
  vector<int> node_id(n);
  for (int i = 0; i < n; i++) {
    node_id[i] = ac.add_string(ss[i]);
  }
  ac.build();
  vector<multiset<int>> vs(ac.size());
  vector<int> val(n);
  SegmentTree<int> seg(
      ac.size(), [](int x, int y) { return max(x, y); }, -1);
  HeavyLightDecomposition hld(ac.size());
  for (int i = 1; i < ac.size(); i++) {
    assert(ac[i].suf_link != -1);
    hld.add_edge(i, ac[i].suf_link);
  }
  hld.init();
  for (int i = 0; i < n; i++) {
    hld.update(seg, node_id[i], 0);
    val[i] = 0;
    vs[node_id[i]].insert(0);
  }
  for (int q = 0; q < m; q++) {
    int type;
    cin >> type;
    if (type == 1) {
      int idx, x;
      cin >> idx >> x;
      idx--;
      auto it = vs[node_id[idx]].find(val[idx]);
      vs[node_id[idx]].erase(it);
      val[idx] = x;
      vs[node_id[idx]].insert(x);
      hld.update(seg, node_id[idx], *vs[node_id[idx]].rbegin());
    } else {
      string s;
      cin >> s;
      int cur = 0;
      int ans = -1;
      for (int i = 0; i < s.size(); i++) {
        cur = ac.go(cur, s[i]);
        chmax(ans, hld.solve(seg, cur));
      }
      cout << ans << "\n";
    }
  }
  return;
}
int main() {
  fastio();
  solve();
  return 0;
}