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 JAVA):

Solution:
import java.io.*;
import java.util.*;

public class G {
	public static void main (String[] args) { new G(); }

	public G() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");

		int n = fs.nextInt();
		int q = fs.nextInt();
		String[] pats = new String[n];
		for(int i = 0; i < n; i++) {
			pats[i] = fs.next();
		}
		terminalSpot = new int[n];
		
		ac = new AhoCorasick();
		ac.createAhoCorasick(pats);
		int M = ac.nodeCount;
		
		TreeSet<Pair>[] ends = new TreeSet[M];
		for(int i = 0; i < M; i++) ends[i] = new TreeSet<>();
		for(int i = 0; i < n; i++) {
			ends[terminalSpot[i]].add(new Pair(i, 0));
		}
		int[] prevMax = new int[n];
		
		subSize = new int[M];
		dfs(0);
		
		chainID = new int[M];
		parentOfChain = new int[M];
		hld = new int[M];
		map = new int[M];
		chainHead = new int[M];
		curChain = 0;
		idxPtr = 0;
		
		dfs2(0);
		
		Pair tmp = new Pair(-1, -1);
		st = new ST_(M);
		for(int qq = 1; qq <= q; qq++) {
			int type = fs.nextInt();
			if(type == 2) {
				char[] str = fs.next().toCharArray();
				int cur = 0, res = -1;
				for(char ch : str) {
					int idx = ch-'a';
					cur = ac.transition[idx][cur];
					
					int val = queryPath(cur);
//					System.out.println("? " + cur + " " + val + " " + ac.term[cur]);
					res = Math.max(res, val);
				}
				
				out.println(res);
			}
			else {
				int idx = fs.nextInt()-1;
				int spot = terminalSpot[idx];
				
				tmp.idx = idx; tmp.val = prevMax[idx];
				ends[spot].remove(tmp);
				
				int val = fs.nextInt();
				ends[spot].add(new Pair(idx, val));
				prevMax[idx] = val;
				
				st.pointUpdate(1, map[terminalSpot[idx]], ends[spot].first().val);
			}
		}
		
		
		out.close();
	}
	
	void dfs(int u) {
		subSize[u] = 1;
		for(int v : adj[u]) {
			dfs(v);
			subSize[u] += subSize[v];
		}
	}
	void dfs2(int u) {
		chainID[u] = curChain;
		map[u] = idxPtr;
		hld[idxPtr++] = u;
		
		if(adj[u].isEmpty()) return;
		int bigKid = adj[u].get(0);
		for(int i = 1; i < adj[u].size(); i++) {
			int v = adj[u].get(i);
			if(subSize[v] > subSize[bigKid]) {
				bigKid = v;
			}
		}
		dfs2(bigKid);

		for(int v : adj[u]) if(v != bigKid) {
			curChain++;
			chainHead[curChain] = v;
			parentOfChain[curChain] = u;
			dfs2(v);
		}
		
	}
	
	int queryPath(int u) {
		int res = -1;
		boolean print = u == 16;
		
		int cur = u;
		while(chainID[cur] != 0) {
			int myChain = chainID[cur];
			int L = map[chainHead[myChain]];
			int R = map[cur];
			
			res = Math.max(res, st.rangeMax(1, L, R));
			
			cur = parentOfChain[myChain];
		}
		
		int L = map[0];
		int R = map[cur];
		res = Math.max(res, st.rangeMax(1, L, R));
		
		return res;
	}
	
	int[] subSize, terminalSpot;
	int[] chainID, parentOfChain, hld, map, chainHead;
	int curChain, idxPtr;
	ST_ st;
	
	AhoCorasick ac;
	ArrayList<Integer>[] adj;
	
	class ST_ {
		int[] L, R, max;
		int size;
		ST_(int n) {
			size = 4 * n + 100;
			L = new int[size];
			R = new int[size];
			max = new int[size];
			init(1, 0, n-1);
		}
		void init(int p, int l, int r) {
			L[p] = l;
			R[p] = r;
			if(l == r) {
				max[p] = ac.term[hld[l]];
				return;
			}
			int mid = (l+r)/2;
			
			init(2 * p, l, mid);
			init(2 * p + 1, mid+1, r);
			update(p);
		}
		void pointUpdate(int p, int idx, int val) {
			if(L[p] == R[p]) {
				max[p] = val;
				return;
			}
			if(idx <= R[2 * p]) pointUpdate(2 * p, idx, val);
			else pointUpdate(2 * p + 1, idx, val);
			update(p);
		}
		int rangeMax(int p, int ll, int rr) {
			if(rr < L[p] || R[p] < ll) return -1;
			if(ll <= L[p] && R[p] <= rr) return max[p];
			
			return Math.max(rangeMax(2 * p, ll, rr), rangeMax(2 * p + 1, ll, rr));
		}
		void update(int p) {
			max[p] = Math.max(max[2 * p], max[2 * p + 1]);
		}
	}
	
	
	class AhoCorasick {
		static final int ALPHA = 26;
		int nodeCount, transition[][];
		int[] term;
		void createAhoCorasick(String[] strs) {
			int maxNodes = 1;
			for(String s : strs) maxNodes += s.length();

			int[][] children = new int[ALPHA][maxNodes];
			int[] leaf = new int[maxNodes];
			Arrays.fill(leaf, -1);
			nodeCount = 1;
			for(int i = 0; i < strs.length; i++) {
				String s = strs[i];
				int node = 0;
				for(char ch : s.toCharArray()) {
					int c = ch - 'a';
					if(children[c][node] == 0) children[c][node] = nodeCount++;
					node = children[c][node];
				}
				leaf[node] = 0;
				terminalSpot[i] = node;
			}
//			System.out.println(Arrays.toString(leaf));

			transition = new int[ALPHA][nodeCount];
			term = new int[nodeCount];
			Arrays.fill(term, -1);

			ArrayDeque<Integer> queue = new ArrayDeque<>();
			queue.add(0);  queue.add(0);
			
			adj = new ArrayList[nodeCount];
			for(int i = 0; i < nodeCount; i++) adj[i] = new ArrayList<>();
			
			while(queue.size() > 0) {
				int node = queue.remove(), suffLink = queue.remove();
				if(node != suffLink) adj[suffLink].add(node);

				term[node] = Math.max(leaf[node] , term[suffLink]);

				for(int ch = 0; ch < ALPHA; ch++) {
					if(children[ch][node] != 0){
						transition[ch][node] = children[ch][node];
						queue.add(children[ch][node]);
						queue.add(node == 0 ? 0 : transition[ch][suffLink]);
					} else  transition[ch][node] = transition[ch][suffLink];
				}
			}
//			System.out.println(Arrays.toString(term));
		}
	}
	
	class Pair implements Comparable<Pair> {
		int idx, val;
		Pair(int i, int v) {
			idx = i;
			val = v;
		}
		public int compareTo(Pair p) {
			int c = Integer.compare(p.val, val);
			if(c == 0) c = Integer.compare(idx, p.idx);
			return c;
		}
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) {
			try {
				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
			}
			catch (Exception e) {
				in = new BufferedInputStream(System.in, BS);
			}
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}