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>
vector<T> ReadVec(const int count, const T inc = 0) {
  vector<T> res(count);
  for (int i = 0; i < int(count); i++) {
    std::cin >> res[i];
    res[i] += inc;
  }
  return res;
}
template <class T>
void PrintVecOneLine(const vector<T>& src) {
  for (int i = 0; i < int(src.size()); i++) {
    std::cout << src[i];
    if (i + 1 != src.size()) std::cout << " ";
  }
  std::cout << "\n";
}
template <class T>
void PrintVecManyLine(const vector<T>& src) {
  for (int i = 0; i < int(src.size()); i++) {
    std::cout << src[i] << "\n";
  }
}
std::vector<std::vector<int>> BuildGraph(int n, int m, bool oriented,
                                         int inc = 1) {
  std::vector<std::vector<int>> res(n);
  for (int i = 0; i < int(m); i++) {
    int a, b;
    std::cin >> a >> b;
    res[a - inc].push_back(b - inc);
    if (oriented) continue;
    res[b - inc].push_back(a - inc);
  }
  return res;
}
std::vector<std::vector<int>> BuildGraph(int n, int m, bool oriented,
                                         std::vector<int64_t>& weight,
                                         int inc = 1) {
  std::vector<std::vector<int>> res(n);
  weight.resize(m);
  for (int i = 0; i < int(m); i++) {
    int a, b;
    std::cin >> a >> b >> weight[i];
    res[a - inc].push_back(b - inc);
    if (oriented) continue;
    res[b - inc].push_back(a - inc);
  }
  return res;
}
namespace dmAlgorithm {
template <const size_t alphabetSize, class StrType>
class dmAchoCorasic {
  struct Node {
    Node() { std::fill(child.begin(), child.end(), -1); }
    std::array<int, alphabetSize> child;
    int link = 0;
    int count = 0;
    int wordIdx = -1;
    int endWord = -1;
    bool isLeaf = false;
    multiset<int> value;
  };

 public:
  dmAchoCorasic(
      const std::vector<StrType>& words,
      const std::function<int(const typename StrType::value_type)>& getValue)
      : m_nodes(1, Node()), m_wordCount(0), m_getValue(getValue) {
    for (int i = 0; i < words.size(); ++i) {
      Add(words[i], i);
    }
    UpdateSuffixLinks();
  }
  dmAchoCorasic(
      const std::function<int(const typename StrType::value_type)>& getValue)
      : m_nodes(1, Node()), m_wordCount(0), m_getValue(getValue) {}
  void Add(const StrType& src, const int wordIdx = -1) {
    int currentNode = 0;
    for (const auto& symbol : src) {
      const int symbolId = m_getValue(symbol);
      if (m_nodes[currentNode].child[symbolId] == -1) {
        m_nodes[currentNode].child[symbolId] = m_nodes.size();
        m_nodes.push_back(Node());
      }
      currentNode = m_nodes[currentNode].child[symbolId];
    }
    m_nodes[currentNode].count++;
    m_nodes[currentNode].isLeaf = true;
    if (m_nodes[currentNode].wordIdx < 0) {
      m_nodes[currentNode].wordIdx = wordIdx < 0 ? m_wordCount : wordIdx;
    }
    m_wordIdxToNodeMap.push_back(currentNode);
    ++m_wordCount;
  }
  int64_t GetTotalMatchesCount(const StrType& text) const {
    int64_t matches = 0;
    int current = 0;
    for (const auto& symbol : text) {
      current = GetLink(current, symbol);
      matches += m_nodes[current].count;
    }
    return matches;
  }
  void UpdateValue(int idx, const int value, const int oldValue) {
    int currentNode = m_wordIdxToNodeMap[idx];
    if (m_nodes[currentNode].value.find(oldValue) !=
        m_nodes[currentNode].value.end())
      m_nodes[currentNode].value.erase(
          m_nodes[currentNode].value.find(oldValue));
    m_nodes[currentNode].value.insert(value);
  }
  int GetMax(const StrType& text) {
    int maxValue = -1;
    int current = 0;
    for (const auto& c : text) {
      current = GetLink(current, c);
      int nodeEnd =
          m_nodes[current].isLeaf ? current : m_nodes[current].endWord;
      while (nodeEnd > 0) {
        if (m_nodes[nodeEnd].value.empty()) {
          maxValue = max(maxValue, 0);
        } else {
          maxValue = max(maxValue, *m_nodes[nodeEnd].value.rbegin());
        }
        nodeEnd = m_nodes[nodeEnd].endWord;
      }
    }
    return maxValue;
  }
  vector<int> GetMatchesCountPerWord(const StrType& src) const {
    vector<int> matches(m_wordCount, 0);
    int current = 0;
    for (const auto& symbol : src) {
      current = GetLink(current, symbol);
      const int nodeEnd =
          m_nodes[current].isLeaf ? current : m_nodes[current].endWord;
      if (nodeEnd >= 0) matches[m_nodes[nodeEnd].wordIdx]++;
    }
    return matches;
  }
  vector<int> GetMatchesCountByPos(const StrType& text) const {
    vector<int> matches(text.size());
    int current = 0;
    int idx = 0;
    for (auto c : text) {
      current = GetLink(current, c);
      matches[idx++] = m_nodes[current].count;
    }
    return matches;
  }

 private:
  int GetLinkById(int curLink, const int symbolId) const {
    int result = 0;
    for (result = m_nodes[curLink].child[symbolId]; curLink >= 0 && result < 0;
         result = curLink < 0 ? result : m_nodes[curLink].child[symbolId]) {
      curLink = m_nodes[curLink].link;
    }
    return curLink < 0 ? 0 : result;
  }
  int GetLink(int curLink, const typename StrType::value_type symbol) const {
    return GetLinkById(curLink, m_getValue(symbol));
  }
  void UpdateSuffixLinks() {
    queue<int> que;
    que.push(0);
    m_nodes[0].link = -1;
    while (!que.empty()) {
      const int pos = que.front();
      que.pop();
      for (int i = 0; i < alphabetSize; ++i) {
        if (m_nodes[pos].child[i] == -1) continue;
        int next = m_nodes[pos].link;
        while (next != -1 && m_nodes[next].child[i] == -1) {
          next = m_nodes[next].link;
        }
        if (next == -1) {
          m_nodes[m_nodes[pos].child[i]].link = 0;
        } else {
          const int child = m_nodes[pos].child[i];
          m_nodes[child].link = m_nodes[next].child[i];
          m_nodes[child].count += m_nodes[m_nodes[child].link].count;
        }
        que.push(m_nodes[pos].child[i]);
      }
      Node& cur = m_nodes[pos];
      const Node& link = m_nodes[cur.link < 0 ? 0 : cur.link];
      cur.endWord = link.isLeaf ? cur.link : link.endWord;
    }
  }
  std::vector<Node> m_nodes;
  size_t m_wordCount;
  std::function<int(const typename StrType::value_type)> m_getValue;
  std::vector<int> m_wordIdxToNodeMap;
};
}  // namespace dmAlgorithm
int main() {
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  std::cout.tie(0);
  std::cout.setf(std::ios::fixed);
  std::cout.precision(20);
  int64_t n, q;
  cin >> n >> q;
  vector<string> words;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    words.push_back(s);
  }
  dmAlgorithm::dmAchoCorasic<26, string> achoc(
      words, [](const char src) { return int(src - 'a'); });
  vector<int> values(words.size(), 0);
  for (int i = 0; i < q; ++i) {
    int type;
    cin >> type;
    if (type == 1) {
      int idx, value;
      cin >> idx >> value;
      achoc.UpdateValue(idx - 1, value, values[idx - 1]);
      values[idx - 1] = value;
    } else {
      string query;
      cin >> query;
      cout << achoc.GetMax(query) << "\n";
    }
  }
  return 0;
}