#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int stk[N], top;
struct BIT {
  int n, w[N << 1];
  inline void mdf(int x, int d) {
    while (x < n) {
      w[x] += d, x += x & -x;
    }
  }
  inline int qry(int x) {
    int res = 0;
    while (x) {
      res += w[x], x -= (x & -x);
    }
    return res;
  }
} bit;
int n, m, colcnt, id[N];
struct LCT {
  int ch[N][2], fa[N], sz[N], rev[N], tag[N], col[N];
  inline bool get(int x) { return x == ch[fa[x]][1]; }
  inline bool is_root(int x) {
    return (x != ch[fa[x]][0]) && (x != ch[fa[x]][1]);
  }
  inline void update(int x) {
    if (x) sz[x] = sz[ch[x][0]] + sz[ch[x][1]] + 1;
  }
  inline void rv(int x) {
    if (x) swap(ch[x][0], ch[x][1]), rev[x] ^= 1;
  }
  inline void cov(int x, int y) { col[x] = tag[x] = y; }
  inline void pushdown(int x) {
    if (rev[x]) rv(ch[x][0]), rv(ch[x][1]), rev[x] = 0;
    if (tag[x]) cov(ch[x][0], tag[x]), cov(ch[x][1], tag[x]), tag[x] = 0;
  }
  inline void rotate(int x) {
    int y = fa[x], z = fa[y], k = get(x);
    fa[x] = z;
    if (!is_root(y)) ch[z][get(y)] = x;
    fa[ch[x][k ^ 1]] = y, ch[y][k] = ch[x][k ^ 1], fa[y] = x, ch[x][k ^ 1] = y,
                 update(y), update(x);
  }
  inline void splay(int x) {
    stk[top = 1] = x;
    for (int i = x; !is_root(i); i = fa[i]) stk[++top] = fa[i];
    while (top) pushdown(stk[top--]);
    for (int y; !is_root(x); rotate(x))
      if (!is_root(y = fa[x])) rotate(get(y) == get(x) ? y : x);
  }
  void print() {
    printf("--------print--------\n");
    for (int i = 1; i <= n; ++i)
      printf("%d: %d %d %d %d %d\n", i, ch[i][0], ch[i][1], sz[i], col[i],
             rev[i]);
    printf("---------end---------\n");
  }
  inline void access(int x, int y) {
    for (int i = 0; x; i = x, x = fa[x]) {
      splay(x), pushdown(x), ch[x][1] = 0, update(x);
      bit.mdf(col[x], -sz[x]), cov(x, y), bit.mdf(col[x], sz[x]);
      ch[x][1] = i, update(x);
    }
  }
  inline void evert(int x, int y) { access(x, y), splay(x), rv(x); }
  inline void nwcol(int x, int y) {
    pushdown(x), ch[x][1] = 0, update(x);
    bit.mdf(col[x], -1), cov(x, y), bit.mdf(col[x], 1);
  }
  inline int qry(int x) {
    splay(x);
    return bit.qry(col[x]) - sz[ch[x][0]];
  }
} lct;
struct Edge {
  int v, next;
} edge[N << 1];
int head[N], esize;
inline void addedge(int x, int y) {
  edge[++esize] = (Edge){y, head[x]}, head[x] = esize;
}
void dfs(int x, int ff) {
  id[x] = x, lct.sz[x] = 1;
  for (int i = head[x], vv; ~i; i = edge[i].next) {
    vv = edge[i].v;
    if (vv == ff) continue;
    dfs(vv, x), lct.fa[vv] = x, id[x] = max(id[vv], id[x]);
  }
  for (int i = head[x], vv; ~i; i = edge[i].next) {
    vv = edge[i].v;
    if (vv == ff) continue;
    if (id[vv] == id[x]) {
      lct.ch[x][1] = vv, lct.sz[x] += lct.sz[vv];
      break;
    }
  }
  lct.col[x] = id[x], bit.mdf(id[x], 1);
}
int main() {
  memset(head, -1, sizeof(head));
  scanf("%d%d", &n, &m);
  bit.n = (n + m);
  for (int i = 1, x, y; i < n; ++i)
    scanf("%d%d", &x, &y), addedge(x, y), addedge(y, x);
  dfs(n, 0);
  char opt[20];
  int x, y;
  colcnt = n;
  for (int i = 1; i <= m; ++i) {
    scanf("%s", opt + 1);
    if (opt[1] == 'u') {
      scanf("%d", &x);
      lct.evert(x, colcnt), lct.nwcol(x, ++colcnt);
    } else if (opt[1] == 'w') {
      scanf("%d", &x);
      printf("%d\n", lct.qry(x));
    } else {
      scanf("%d%d", &x, &y);
      printf("%d\n", (lct.qry(x) < lct.qry(y)) ? x : y);
    }
  }
  return 0;
}
