#include #include using namespace std; struct Node { char l; Node *parent; }; int n,m, x, y, c, p, ans; char l; vector tree; long long f[30]; void odd(int s, int s2, bool last=true) { Node *p = tree[s]; if (p == NULL) return; while (p->parent != NULL) { if (p == tree[s2]) { last = false; break; } f[p->l - 'a']++; p = p->parent; } if (last) f[p->l - 'a']++; } int main () { scanf("%d %d\n", &n, &m); tree.push_back(new Node); for (int i=0; il); tree[i+1]->parent = NULL; } scanf("%c", &l); for (int i=0; iparent = tree[x]; } ++n; for (;m;--m) { scanf("%d ", &c); if (c == 2) { scanf("%d %c", &p, &l); tree.push_back(new Node); tree[n]->l = l; tree[n]->parent = tree[p]; ++n; } else if (c == 1) { for (int i=0; i<30; ++i) f[i] = 0; scanf("%d %d", &x, &y); odd(x, y); odd(y, x, false); ans = 0; for (int i=0; i<26; ++i) if (f[i] %2 == 1) ans++; printf("%d\n", ans); } } return 0; }