#include <bits/stdc++.h>
using namespace std;
const int N = 200200;
int n, Q, cc = 1, tp, h[N], s[N];
struct E {
  int v, nxt;
} e[N << 1];
inline void add(int u, int v) {
  e[cc] = (E){v, h[u]};
  h[u] = cc++;
}
struct st {
  int n, c[N << 1];
  inline void upd(int x, int v) {
    for (; x <= n; x += x & -x) c[x] += v;
  }
  inline int qry(int x) {
    int r = 0;
    for (; x; x -= x & -x) r += c[x];
    return r;
  }
} C;
struct tr {
  int ch[2], f, r, sz, c, tg;
} t[N];
inline int isrt(int x) { return t[t[x].f].ch[0] != x && t[t[x].f].ch[1] != x; }
inline int wh(int x) { return t[t[x].f].ch[1] == x; }
inline void up(int x) { t[x].sz = t[t[x].ch[0]].sz + t[t[x].ch[1]].sz + 1; }
inline void rot(int x) {
  int y = t[x].f, z = t[y].f, c = wh(x);
  t[x].f = z;
  if (!isrt(y)) t[z].ch[wh(y)] = x;
  t[t[x].ch[c ^ 1]].f = y;
  t[y].ch[c] = t[x].ch[c ^ 1];
  t[y].f = x;
  t[x].ch[c ^ 1] = y;
  up(y);
  up(x);
}
inline void rev(int x) {
  swap(t[x].ch[0], t[x].ch[1]);
  t[x].r ^= 1;
}
inline void cov(int x, int v) { t[x].c = t[x].tg = v; }
inline void dn(int x) {
  if (t[x].r) rev(t[x].ch[0]), rev(t[x].ch[1]), t[x].r ^= 1;
  if (t[x].tg) cov(t[x].ch[0], t[x].tg), cov(t[x].ch[1], t[x].tg), t[x].tg = 0;
}
inline void splay(int x) {
  for (int i = s[tp = 1] = x; !isrt(i); i = t[i].f) s[++tp] = t[i].f;
  while (tp) dn(s[tp--]);
  for (int y; !isrt(x); rot(x))
    if (!isrt(y = t[x].f)) wh(x) ^ wh(y) ? rot(x) : rot(y);
}
inline void access(int x, int c) {
  for (int y = 0; x; x = t[y = x].f) {
    splay(x);
    t[x].ch[1] = 0;
    up(x);
    C.upd(t[x].c, -t[x].sz);
    cov(x, c);
    C.upd(t[x].c, t[x].sz);
    t[x].ch[1] = y;
    up(x);
  }
}
inline int qry(int x) {
  splay(x);
  return C.qry(t[x].c) - t[t[x].ch[0]].sz;
}
void dfs(int x, int p) {
  t[x].c = x;
  t[x].sz = 1;
  t[x].f = p;
  for (int i = h[x]; i; i = e[i].nxt)
    if (e[i].v != p) dfs(e[i].v, x), t[x].c = max(t[x].c, t[e[i].v].c);
  for (int i = h[x]; i; i = e[i].nxt)
    if (e[i].v != p && t[x].c == t[e[i].v].c)
      t[x].ch[1] = e[i].v, t[x].sz += t[e[i].v].sz;
  C.upd(t[x].c, 1);
}
int main() {
  scanf("%d%d", &n, &Q);
  C.n = n + Q + 1;
  for (int i = 1, u, v; i < n; i++) scanf("%d%d", &u, &v), add(u, v), add(v, u);
  dfs(n, 0);
  int c = n;
  while (Q--) {
    char o[10];
    scanf("%s", o);
    int x, y;
    if (o[0] == 'u') {
      scanf("%d", &x);
      access(x, c);
      splay(x);
      rev(x);
      dn(x);
      C.upd(t[x].c, -1);
      t[x].ch[1] = 0;
      cov(x, ++c);
      t[x].sz = 1;
      C.upd(t[x].c, 1);
    } else if (o[0] == 'w')
      scanf("%d", &x), printf("%d\n", qry(x));
    else {
      scanf("%d%d", &x, &y);
      printf("%d\n", qry(x) < qry(y) ? x : y);
    }
  }
  return 0;
}
