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;
int inf;
const double eps = 1e-8;
const double pi = acos(-1.0);
template <class T, class T2>
int chkmin(T &a, T2 b) {
  return a > b ? a = b, 1 : 0;
}
template <class T, class T2>
int chkmax(T &a, T2 b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
T sqr(T a) {
  return a * a;
}
template <class T, class T2>
T mmin(T a, T2 b) {
  return a < b ? a : b;
}
template <class T, class T2>
T mmax(T a, T2 b) {
  return a > b ? a : b;
}
template <class T>
T aabs(T a) {
  return a < 0 ? -a : a;
}
template <class T>
int dcmp(T a, T b) {
  return a > b;
}
template <int *a>
int cmp_a(int first, int second) {
  return a[first] < a[second];
}
struct __INIT__ {
  __INIT__() {
    fill((unsigned char *)(&inf), (unsigned char *)(&inf) + sizeof(inf), 0x3f);
  }
} __INIT___;
namespace io {
const int SIZE = (1 << 21) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c,
                                       qu[55];
int f, qr;
inline void flush() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
}
inline void putc(char first) {
  *oS++ = first;
  if (oS == oT) flush();
}
template <typename A>
inline bool read(A &first) {
  for (f = 1, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                            : *iS++);
       c < '0' || c > '9';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    if (c == '-')
      f = -1;
    else if (c == EOF)
      return 0;
  for (first = 0; c <= '9' && c >= '0';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    first = first * 10 + (c & 15);
  first *= f;
  return 1;
}
inline bool read(char &first) {
  while ((first = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                               (iS == iT ? EOF : *iS++))
                            : *iS++)) == ' ' ||
         first == '\n' || first == '\r')
    ;
  return first != EOF;
}
inline bool read(char *first) {
  while ((*first = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                                (iS == iT ? EOF : *iS++))
                             : *iS++)) == '\n' ||
         *first == ' ' || *first == '\r')
    ;
  if (*first == EOF) return 0;
  while (!(*first == '\n' || *first == ' ' || *first == '\r' || *first == EOF))
    *(++first) = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                           : *iS++);
  *first = 0;
  return 1;
}
template <typename A, typename... B>
inline bool read(A &first, B &...second) {
  return read(first) && read(second...);
}
template <typename A>
inline bool write(A first) {
  if (!first) putc('0');
  if (first < 0) putc('-'), first = -first;
  while (first) qu[++qr] = first % 10 + '0', first /= 10;
  while (qr) putc(qu[qr--]);
  return 0;
}
inline bool write(char first) {
  putc(first);
  return 0;
}
inline bool write(const char *first) {
  while (*first) {
    putc(*first);
    ++first;
  }
  return 0;
}
inline bool write(char *first) {
  while (*first) {
    putc(*first);
    ++first;
  }
  return 0;
}
template <typename A, typename... B>
inline bool write(A first, B... second) {
  return write(first) || write(second...);
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_flusher_;
}  // namespace io
using io ::putc;
using io ::read;
using io ::write;
char s[600005];
int to[600005][27], t = 1, fail[600005];
int id[600005], val[600005];
int mx[600005];
multiset<int> st[600005];
int a[600005];
int ins(char *s) {
  int at = 1;
  while (*s) {
    if (!to[at][*s - 'a']) val[to[at][*s - 'a'] = ++t] = -inf;
    at = to[at][*s - 'a'];
    ++s;
  }
  val[at] = 0;
  st[at].insert(0);
  return at;
}
int q[600005], *l, *r;
vector<int> nxt[600005];
int siz[600005], hvy[600005], mxs[600005];
void dfs(int first) {
  siz[first] = 1;
  for (auto i : nxt[first]) {
    dfs(i);
    siz[first] += siz[i];
    if (chkmax(mxs[first], siz[i])) hvy[first] = i;
  }
}
int c;
int top[600005], xid[600005], ct, dfn[600005];
int mxdp[600005];
int dep[600005];
int fa[600005];
int ls[600005], rs[600005], rt[600005], xsiz[600005], li[600005];
int build(int l, int r) {
  if (l > r) return 0;
  if (l == r) {
    mx[li[l]] = val[li[l]];
    return li[l];
  }
  int mid;
  int xl = l, xr = r;
  mid = (xl + xr) >> 1;
  while (xl <= xr) {
    mid = (xl + xr) >> 1;
    if ((xsiz[mid] - xsiz[r]) << 1 >= xsiz[l] - xsiz[r])
      xl = mid + 1;
    else
      xr = mid - 1;
  }
  mid = xl - 1;
  int first = li[mid];
  fa[ls[first] = build(l, mid - 1)] = first;
  fa[rs[first] = build(mid + 1, r)] = first;
  mx[first] = mmax(val[first], mmax(mx[ls[first]], mx[rs[first]]));
  return first;
}
int dfs2(int first) {
  if (!top[first]) {
    top[first] = first;
  }
  xid[++ct] = first;
  dfn[first] = ct;
  chkmax(mxdp[top[first]], dep[first]);
  if (hvy[first]) {
    top[hvy[first]] = top[first];
    dep[hvy[first]] = dep[first] + 1;
    dfs2(hvy[first]);
    for (auto i : nxt[first])
      if (i != hvy[first]) {
        dep[i] = dep[first] + 1;
        fa[dfs2(i)] = first;
      }
  }
  if (top[first] == first) {
    c = mxdp[first] - dep[first] + 1;
    for (int i = 0; i < c; ++i) {
      li[i + 1] = xid[dfn[first] + i];
      xsiz[i + 1] = siz[li[i + 1]];
    }
    int second = build(1, c);
    rt[second] = 1;
    return second;
  } else
    return 0;
}
void build() {
  l = q + 1;
  r = q;
  fail[1] = 1;
  for (int i = 0; i < 26; ++i)
    if (!to[1][i])
      to[1][i] = 1;
    else {
      fail[to[1][i]] = 1;
      *(++r) = to[1][i];
    }
  for (; l <= r; ++l) {
    for (int i = 0; i < 26; ++i)
      if (!to[*l][i]) {
        to[*l][i] = to[fail[*l]][i];
      } else
        fail[*(++r) = to[*l][i]] = to[fail[*l]][i];
  }
  for (int i = 2; i <= t; ++i) nxt[fail[i]].emplace_back(i);
  mx[0] = -inf;
  mx[1] = val[1] = -inf;
  dfs(1);
  dfs2(1);
}
void upd(int first, int second, int id) {
  st[first].erase(st[first].lower_bound(a[id]));
  st[first].insert(a[id] = second);
  if (val[first] != *st[first].rbegin()) {
    val[first] = *st[first].rbegin();
    while (1) {
      mx[first] = mmax(val[first], mmax(mx[ls[first]], mx[rs[first]]));
      if (rt[first]) return;
      first = fa[first];
    }
  }
}
int query(int first) {
  int second = mmax(val[first], mx[ls[first]]);
  while (fa[first]) {
    if (first != ls[fa[first]]) {
      chkmax(second, mx[ls[fa[first]]]);
      chkmax(second, val[fa[first]]);
    }
    first = fa[first];
  }
  return second;
}
int query(char *s) {
  int at = 1;
  int ans = -1;
  while (*s) {
    at = to[at][*s - 'a'];
    chkmax(ans, query(at));
    ++s;
  }
  return ans;
}
signed main() {
  int n, q;
  read(n, q);
  for (int i = 1; i <= n; ++i) {
    read(s);
    id[i] = ins(s);
  }
  build();
  fa[0] = 0;
  for (; q; --q) {
    int tp, first, second;
    read(tp);
    if (tp == 1) {
      read(first, second);
      upd(id[first], second, first);
    } else {
      read(s);
      write(query(s), '\n');
    }
  }
  return 0;
}