#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const int inf = 1 << 30;   int n, qn, tot = 0, head[N], col[N], nowHead[N], deg[N], seq[N];   int dfsc = 0, id[N], siz[N], fa[N], son[N], dep[N], top[N];   bool vis[N];   struct Edge {     int to, nxt;   } e[N << 1];   inline void add(int from, int to) {     e[++tot].to = to;     e[tot].nxt = head[from];     head[from] = tot;   }   struct Seg {     int l, r, c;     inline Seg(int L = 0, int R = 0, int C = 0) { l = L, r = R, c = C; }     friend bool operator<(const Seg x, const Seg y) { return x.l < y.l; }   };   set<Seg> seg[N];   template <typename T>   inline void read(T &X) {     X = 0;     char ch = 0;     T op = 1;     for (; ch >  9  || ch <  0 ; ch = getchar())       if (ch ==  - ) op = -1;     for (; ch >=  0  && ch <=  9 ; ch = getchar())       X = (X << 3) + (X << 1) + ch - 48;     X *= op;   }   namespace Bit {   int s[N << 1];   inline void modify(int p, int v) {     if (!p) return;     for (; p < (N << 1); p += (p & (-p))) s[p] += v;   }   inline int query(int p) {     int res = 0;     for (; p > 0; p -= (p & (-p))) res += s[p];     return res;   }   }  // namespace Bit   void dfs1(int x, int fat, int depth) {     fa[x] = fat, dep[x] = depth, siz[x] = 1;     int maxson = -1;     for (int i = head[x]; i; i = e[i].nxt) {       int y = e[i].to;       if (y == fat) continue;       dfs1(y, x, depth + 1);       siz[x] += siz[y];       if (siz[y] > maxson) {         maxson = siz[y];         son[x] = y;       }     }   }   void dfs2(int x, int topf) {     top[x] = topf, id[x] = ++dfsc;     if (!son[x]) return;     dfs2(son[x], topf);     for (int i = head[x]; i; i = e[i].nxt) {       int y = e[i].to;       if (y == fa[x] || y == son[x]) continue;       dfs2(y, y);     }   }   inline int getLca(int x, int y) {     for (; top[x] != top[y];) {       if (dep[top[x]] < dep[top[y]]) swap(x, y);       x = fa[top[x]];     }     return dep[x] < dep[y] ? x : y;   }   inline int getDis(int x, int y) {     return dep[x] + dep[y] - 2 * dep[getLca(x, y)];   }   inline set<Seg>::iterator getSeg(set<Seg> &s, int l) {     set<Seg>::iterator it = s.lower_bound(Seg(l, inf, 0));     if (it != s.end() && it->l == l) return it;     --it;     int nowl = it->l, nowr = it->r, nowc = it->c;     s.erase(it);     if (l - 1 >= nowl) s.insert(Seg(nowl, l - 1, nowc));     s.insert(Seg(l, nowr, nowc));     return s.lower_bound(Seg(l, nowr, nowc));   }   inline void ins(set<Seg> &s, int l, int r, int c, int st) {     set<Seg>::iterator itl = getSeg(s, l), itr;     if (r + 1 <= id[st] + siz[st] - 1)       itr = getSeg(s, r + 1);     else       itr = s.end();     for (set<Seg>::iterator it = itl; it != itr; ++it) {       Bit ::modify(it->c, -((it->r) - (it->l) + 1));     }     Bit ::modify(c, r - l + 1);     s.erase(itl, itr), s.insert(Seg(l, r, c));   }   inline void modify(int x, int y, int c) {     nowHead[c] = y;     for (; top[x] != top[y];) {       if (dep[top[x]] < dep[top[y]]) swap(x, y);       ins(seg[top[x]], id[top[x]], id[x], c, top[x]);       x = fa[top[x]];     }     if (dep[x] > dep[y]) swap(x, y);     ins(seg[top[x]], id[x], id[y], c, top[x]);   }   inline int solve(int x) {     int c = getSeg(seg[top[x]], id[x])->c;     return Bit ::query(c - 1) + getDis(x, nowHead[c]) + 1;   }   int main() {     read(n), read(qn);     for (int x, y, i = 1; i < n; i++) {       read(x), read(y);       ++deg[x], ++deg[y];       add(x, y), add(y, x);     }     dfs1(1, 0, 1), dfs2(1, 1);     int cnt = 0;     set<int> q;     for (int i = 1; i <= n; i++)       if (deg[i] == 1) q.insert(i), vis[i] = 1;     for (; !q.empty();) {       int now = (*q.begin());       q.erase(*q.begin());       seq[now] = ++cnt;       nowHead[cnt] = now;       seg[top[now]].insert(Seg(id[now], id[now], cnt));       Bit ::modify(cnt, 1);       for (int i = head[now]; i; i = e[i].nxt) {         if (vis[e[i].to]) continue;         --deg[e[i].to];         if (deg[e[i].to] == 1 && !vis[e[i].to])           q.insert(e[i].to), vis[e[i].to] = 1;       }     }     int lst = n;     for (char op[9]; qn--;) {       scanf( %s , op);       if (op[0] ==  u ) {         int x;         read(x);         modify(x, lst, ++cnt);         lst = x;       }       if (op[0] ==  w ) {         int x;         read(x);         printf( %d n , solve(x));       }       if (op[0] ==  c ) {         int x, y;         read(x), read(y);         printf( %d n , solve(x) < solve(y) ? x : y);       }     }     return 0;   }