#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
const int maxq = 200005;
int n, q;
struct Edge {
  int to, nxt;
} e[maxn << 1];
int first[maxn];
inline void add_edge(int from, int to) {
  static int cnt = 0;
  e[++cnt].nxt = first[from];
  e[cnt].to = to;
  first[from] = cnt;
  e[++cnt].nxt = first[to];
  e[cnt].to = from;
  first[to] = cnt;
}
struct BIT {
  int xx[maxn << 1];
  inline void add(int pla, int x) {
    for (; pla <= n + q; pla += (pla & -pla)) xx[pla] += x;
  }
  inline int query(int pla) {
    int ans = 0;
    for (; pla; pla -= (pla & -pla)) ans += xx[pla];
    return ans;
  }
} tr;
int fa[maxn];
int s[maxn][2];
int siz[maxn];
int col[maxn];
int lzy[maxn];
inline void dfs(int now) {
  col[now] = now;
  siz[now] = 1;
  for (int i = first[now]; i; i = e[i].nxt) {
    register int to = e[i].to;
    if (to != fa[now]) {
      fa[to] = now;
      dfs(to);
      if (col[to] > col[now]) {
        col[now] = col[to];
        s[now][1] = to;
        siz[now] = siz[to] + 1;
      }
    }
  }
  tr.add(col[now], 1);
}
inline bool nroot(int x) { return s[fa[x]][0] == x || s[fa[x]][1] == x; }
inline void push_up(int x) { siz[x] = siz[s[x][0]] + siz[s[x][1]] + 1; }
inline void fan(int x) {
  lzy[x] ^= 1;
  swap(s[x][0], s[x][1]);
}
inline void push_down(int x) {
  if (lzy[x]) {
    lzy[x] = 0;
    if (s[x][0]) fan(s[x][0]);
    if (s[x][1]) fan(s[x][1]);
  }
  if (s[x][0]) col[s[x][0]] = col[x];
  if (s[x][1]) col[s[x][1]] = col[x];
}
inline void rotate(int x) {
  int y = fa[x], z = fa[y];
  int d = s[y][1] == x, k = s[x][!d];
  if (nroot(y)) s[z][s[z][1] == y] = x;
  fa[x] = z;
  s[x][!d] = y;
  fa[y] = x;
  s[y][d] = k;
  if (k) fa[k] = y;
  push_up(y);
  push_up(x);
}
int sta[maxn];
inline void splay(int x) {
  int tx = x;
  int top = 0;
  sta[++top] = tx;
  while (nroot(tx)) sta[++top] = (tx = fa[tx]);
  while (top) push_down(sta[top--]);
  while (nroot(x)) {
    register int y = fa[x];
    if (nroot(y)) {
      register int z = fa[y];
      rotate(((s[z][1] == y) ^ (s[y][1] == x)) ? x : y);
    }
    rotate(x);
  }
}
int nowcol;
inline void access(int x) {
  for (int y = 0; x; x = fa[y = x]) {
    splay(x);
    s[x][1] = 0;
    push_up(x);
    tr.add(col[x], -siz[x]);
    tr.add(nowcol, siz[x]);
    s[x][1] = y;
    push_up(x);
  }
}
inline void make_root(int x) {
  nowcol++;
  access(x);
  splay(x);
  fan(x);
  col[x] = nowcol;
}
char opt[23];
inline int query(int x) {
  splay(x);
  return tr.query(col[x]) - siz[s[x][0]];
}
int main() {
  scanf("%d%d", &n, &q);
  nowcol = n;
  for (int i = 1, f, t; i < n; ++i) {
    scanf("%d%d", &f, &t);
    add_edge(f, t);
  }
  dfs(n);
  int _u, _v;
  for (int i = 1; i <= q; ++i) {
    scanf("%s", opt);
    if (opt[0] == 'u') {
      scanf("%d", &_v);
      make_root(_v);
    } else if (opt[0] == 'w') {
      scanf("%d", &_v);
      printf("%d\n", query(_v));
    } else {
      scanf("%d%d", &_u, &_v);
      int ans1 = query(_u);
      int ans2 = query(_v);
      printf("%d\n", ans1 < ans2 ? _u : _v);
    }
  }
  return 0;
}
