import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Queue; import java.util.Set; public class prog { private class Node { private String name; private int index; public Node(String name) { this.name = name; } } private static Node[] parents = new Node[100000]; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = br.readLine(); String[] split = line.split(" "); int n = Integer.parseInt(split[0]); int m = Integer.parseInt(split[1]); String names = br.readLine(); List ns = new ArrayList(); int length = names.length(); ns.add('0'); for (int i = 1; i <= length; i++) { ns.add(names.charAt(i - 1)); } int nM1 = n - 1; Map> map = new HashMap>(); for (int i = 0; i < nM1; i++) { String s = br.readLine(); String[] spl = s.split(" "); int first = Integer.parseInt(spl[0]); int sec = Integer.parseInt(spl[1]); updateMap(map, first, sec); } int counter = n; for (int i = 0; i < m; i++) { String s = br.readLine(); String[] spl = s.split(" "); int one = Integer.parseInt(spl[0]); if (one == 2) { int newNode = (++counter); int two = Integer.parseInt(spl[1]); char three = spl[2].charAt(0); updateMap(map, two, newNode); ns.add(three); } else { int x = Integer.parseInt(spl[1]); int y = Integer.parseInt(spl[2]); int[] SS = new int[ns.size()]; Arrays.fill(SS, -1); Queue queue = new ArrayDeque(); queue.offer(x); int crt = 0; while (!queue.isEmpty()) { Integer poll = queue.poll(); crt++; List next = map.get(poll); for (Integer nb : next) { if (SS[nb] == -1) { SS[nb] = crt; queue.offer(nb); } } } int len = SS[y]; int [] f = new int['z' - 'a' + 1]; // System.out.println(f.length); Arrays.fill(f, 0); f[ns.get(y) - 'a']++; int hh = y; while (len > 0) { len--; List next = map.get(hh); int nG = -1; for (Integer integer : next) { if (SS[integer] == len) { nG = integer; f[ns.get(nG) - 'a']++; break; } } hh = nG; } f[ns.get(x) - 'a']++; int countLetters = 0; for (int j = 0; j < f.length; j++) { if (f[j] % 2 == 1) { countLetters++; } } System.out.println(countLetters); } } } private static void updateMap(Map> map, int first, int sec) { List ex = map.get(first); if (ex == null) { ArrayList value = new ArrayList(); value.add(sec); map.put(first, value); } else { ex.add(sec); } List ex2 = map.get(sec); if (ex2 == null) { ArrayList value = new ArrayList(); value.add(first); map.put(sec, value); } else { ex2.add(first); } } }