#include <bits/stdc++.h>
using namespace std;
int n, q, arr[400005];
vector<int> G[400005];
void add(int x, int d) {
  for (int i = x; i <= n + q; i += i & -i) arr[i] += d;
}
int qsum(int x) {
  int s = 0;
  for (int i = x; i; i -= i & -i) s += arr[i];
  return s;
}
namespace LCT {
int fa[400005], ch[400005][2], siz[400005], col[400005], tag[400005],
    rev[400005];
inline bool isr(int x) { return ch[fa[x]][0] != x && ch[fa[x]][1] != x; }
inline bool isc(int x) { return ch[fa[x]][1] == x; }
inline void upd(int x) { siz[x] = siz[ch[x][0]] + siz[ch[x][1]] + 1; }
inline void pd(int x) {
  if (rev[x]) {
    swap(ch[x][0], ch[x][1]);
    if (ch[x][0]) rev[ch[x][0]] ^= 1;
    if (ch[x][1]) rev[ch[x][1]] ^= 1;
    rev[x] = 0;
  }
  if (tag[x]) {
    if (ch[x][0]) col[ch[x][0]] = tag[ch[x][0]] = tag[x];
    if (ch[x][1]) col[ch[x][1]] = tag[ch[x][1]] = tag[x];
    tag[x] = 0;
  }
}
inline void pdpath(int x) {
  if (!isr(x)) pdpath(fa[x]);
  pd(x);
}
inline void rot(int x) {
  int y = fa[x], z = fa[y], c = isc(x);
  (!isr(y)) && (ch[z][isc(y)] = x);
  (ch[y][c] = ch[x][!c]) && (fa[ch[y][c]] = y);
  fa[ch[x][!c] = y] = x, fa[x] = z;
  upd(y), upd(x);
}
inline void splay(int x) {
  for (pdpath(x); !isr(x); rot(x))
    if (!isr(fa[x])) rot(isc(fa[x]) == isc(x) ? fa[x] : x);
}
inline void access(int x, int newcol) {
  for (int y = 0; x; x = fa[y = x]) {
    splay(x);
    siz[x] -= siz[ch[x][1]];
    add(col[x], -siz[x]);
    add(col[x] = tag[x] = newcol, siz[x]);
    siz[x] += siz[ch[x][1] = y];
  }
}
}  // namespace LCT
using namespace LCT;
inline int ask(int x) {
  splay(x);
  return qsum(col[x]) - siz[ch[x][0]];
}
void dfs(int u, int pre) {
  siz[u] = 1, col[u] = u, add(u, 1);
  for (int v : G[u])
    if (v != pre) fa[v] = u, dfs(v, u);
}
int main() {
  int x, y;
  char s[10];
  scanf("%d%d", &n, &q);
  for (int i = 1; i < n; i++)
    scanf("%d%d", &x, &y), G[x].push_back(y), G[y].push_back(x);
  dfs(1, 0);
  for (int i = 1; i <= n; i++) access(i, i), splay(i), rev[i] ^= 1;
  while (q--) {
    scanf("%s%d", s, &x);
    if (s[0] == 'u') access(x, ++n), splay(x), rev[x] ^= 1;
    if (s[0] == 'w') printf("%d\n", ask(x));
    if (s[0] == 'c') scanf("%d", &y), printf("%d\n", ask(x) < ask(y) ? x : y);
  }
}
