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("O3", "unroll-loops")
#pragma GCC target("sse4.2")
using namespace std;
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
void flush() { cout << flush; }
void flushln() { cout << endl; }
void println() { cout << '\n'; }
template <class T>
void print(const T &x) {
  cout << x;
}
template <class T>
void read(T &x) {
  cin >> x;
}
template <class T, class... U>
void read(T &x, U &...u) {
  read(x);
  read(u...);
}
template <class T, class... U>
void print(const T &x, const U &...u) {
  print(x);
  print(u...);
}
template <class T, class... U>
void println(const T &x, const U &...u) {
  print(x);
  println(u...);
}
template <class T, class U>
inline bool chmin(T &x, const U &y) {
  return y < x ? x = y, 1 : 0;
}
template <class T, class U>
inline bool chmax(T &x, const U &y) {
  return y > x ? x = y, 1 : 0;
}
template <class T>
inline void sort(T &a) {
  sort((a).begin(), (a).end());
}
template <class T>
inline void rsort(T &a) {
  sort((a).rbegin(), (a).rend());
}
template <class T>
inline void reverse(T &a) {
  reverse((a).begin(), (a).end());
}
template <class T, class U>
inline istream &operator>>(istream &str, pair<T, U> &p) {
  return str >> p.first >> p.second;
}
template <class T>
inline istream &operator>>(istream &str, vector<T> &a) {
  for (auto &i : a) str >> i;
  return str;
}
template <class T>
inline T sorted(T a) {
  sort(a);
  return a;
}
namespace Aho {
const int N = 3e5 + 100;
int ptr = 1;
struct node {
  vector<int> go;
  int suf = 0, par = 0, sup = 0;
  char last;
  multiset<int> st;
  vector<int> term;
  node() { go.resize(26); }
  int getmx() const { return signed((st).size()) == 0 ? -1 : *st.rbegin(); }
};
node t[N];
int addlink(int v, char c) {
  if (t[v].go[c]) return t[v].go[c];
  int u = ptr++;
  t[u].par = v;
  t[u].last = c;
  return t[v].go[c] = u;
}
int getlink(int v, int c) {
  if (t[v].go[c]) return t[v].go[c];
  if (v == 0) return v;
  return getlink(t[v].suf, c);
}
vector<int> pos;
void addstring(const string &second, int ind) {
  int v = 0;
  for (auto i : second) v = addlink(v, i - 'a');
  t[v].term.push_back(ind);
  pos[ind] = v;
}
void countsuf(int v) {
  queue<int> que({v});
  while (signed((que).size())) {
    auto first = que.front();
    que.pop();
    if (t[first].par != 0) {
      t[first].suf = getlink(t[t[first].par].suf, t[first].last);
      if (signed((t[t[first].suf].term).size()))
        t[first].sup = t[first].suf;
      else
        t[first].sup = t[t[first].suf].sup;
    }
    for (int i = 0; i < 26; ++i)
      if (t[first].go[i]) que.push(t[first].go[i]);
  }
}
};  // namespace Aho
namespace HLD {
struct node {
  int mx = -1;
  node() {}
  void a(int k) { mx = k; }
};
node merge(node a, node b) {
  node ans;
  ans.mx = max(a.mx, b.mx);
  return ans;
}
struct Tree {
  static const int n = 1 << 19;
  node t[2 * n + 5];
  void add(int r, int x) {
    r += n;
    t[r].a(x);
    r >>= 1;
    while (r > 0) {
      t[r] = merge(t[r + r], t[r + r + 1]);
      r >>= 1;
    }
  }
  node get(int l, int r) {
    l += n;
    r += n + 1;
    node left, right;
    while (l < r) {
      if (l & 1) left = merge(left, t[l++]);
      if (r & 1) right = merge(t[--r], right);
      l >>= 1;
      r >>= 1;
    }
    return merge(left, right);
  }
} t;
vector<int> h, sub, ind, head, par;
int curr = 0;
vector<vector<int>> G;
void orient(int v = 0, int p = -1, int d = 0) {
  h[v] = d;
  par[v] = p;
  sub[v] = 1;
  for (auto i : G[v])
    if (i != p) {
      orient(i, v, d + 1);
      sub[v] += sub[i];
    }
  for (int i = 0; i < signed((G[v]).size()); ++i)
    if (G[v][i] != p && sub[G[v][i]] * 2 >= sub[v]) swap(G[v][0], G[v][i]);
}
void buildhld(int v = 0, int path = 0) {
  head[v] = path;
  ind[v] = curr++;
  for (auto i : G[v])
    if (i != par[v]) {
      if (sub[i] * 2 >= sub[v])
        buildhld(i, path);
      else
        buildhld(i, i);
    }
}
int lca(int u, int v) {
  while (head[u] != head[v])
    if (h[head[u]] > h[head[v]])
      u = par[head[u]];
    else
      v = par[head[v]];
  return h[u] < h[v] ? u : v;
}
node getw(int u, int v) {
  node ans;
  while (head[u] != head[v])
    ans = merge(ans, t.get(ind[head[u]], ind[u])), u = par[head[u]];
  return merge(ans, t.get(ind[v], ind[u]));
}
node getwo(int u, int v) {
  node ans;
  while (head[u] != head[v])
    ans = merge(ans, t.get(ind[head[u]], ind[u])), u = par[head[u]];
  if (ind[v] + 1 > ind[u]) return ans;
  return merge(ans, t.get(ind[v] + 1, ind[u]));
}
void resize(int n) {
  G = vector<vector<int>>(n);
  h = sub = ind = head = par = vector<int>(n);
}
};  // namespace HLD
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12);
  int n, m;
  read(n, m);
  Aho::pos.resize(n);
  for (int i = 0; i < n; ++i) {
    string second;
    read(second);
    Aho::addstring(second, i);
  }
  Aho::countsuf(0);
  vector<int> val(n);
  for (int i = 0; i < n; ++i) Aho::t[Aho::pos[i]].st.insert(0);
  HLD::resize(Aho::ptr);
  for (int i = 1; i < Aho::ptr; ++i) {
    int u = Aho::t[i].suf, v = i;
    0;
    HLD::G[u].push_back(v);
  }
  HLD::orient(0);
  HLD::buildhld(0);
  for (int i = 0; i < Aho::ptr; ++i) {
    0;
    HLD::t.add(HLD::ind[i], Aho::t[i].getmx());
  }
  while (m--) {
    int mode;
    read(mode);
    if (mode == 1) {
      int i, v;
      read(i, v);
      --i;
      int p = Aho::pos[i];
      Aho::t[p].st.erase(Aho::t[p].st.find(val[i]));
      val[i] = v;
      Aho::t[p].st.insert(val[i]);
      HLD::t.add(HLD::ind[p], Aho::t[p].getmx());
    }
    if (mode == 2) {
      string q;
      read(q);
      int ans = -1;
      int v = 0;
      for (auto i : q) {
        v = Aho::getlink(v, i - 'a');
        chmax(ans, HLD::getw(v, 0).mx);
      }
      println(ans);
    }
  }
  return 0;
}