#include <bits/stdc++.h>
inline void swap(int& x, int& y) {
  int z = x;
  x = y, y = z;
}
int a[200002], b[400004], c[400004], e[200002][2], f[200002], k, m, n,
    o[200002], p, s[200002], t;
inline void add(int u, int v) {
  if (u)
    while (u <= t) c[u] += v, u += u & -u;
}
inline int sum(int u) {
  int v = 0;
  while (u) v += c[u], u ^= u & -u;
  return v;
}
inline bool nroot(int u) { return e[f[u]][0] == u || e[f[u]][1] == u; }
inline void up(int u) { s[u] = s[e[u][0]] + s[e[u][1]] + 1; }
inline void swap(int u) { swap(e[u][0], e[u][1]), b[u] ^= 1; }
inline void down(int u) {
  if (b[u]) swap(e[u][0]), swap(e[u][1]), b[u] = 0;
  a[e[u][0]] = a[e[u][1]] = a[u];
}
inline void rotate(int u) {
  int z = e[f[u]][1] == u, v = f[u], g = f[v], h = e[u][z ^ 1];
  if (f[u] = g, nroot(v)) e[g][e[g][1] == v] = u;
  up(e[f[f[e[v][z] = h] = v] = u][z ^ 1] = v);
}
inline void splay(int u) {
  for (int v = o[++p] = u; nroot(v); v = o[++p] = f[v])
    ;
  while (p) down(o[p--]);
  for (int v = f[u], g = f[v]; nroot(u); rotate(u), v = f[u], g = f[v])
    if (nroot(v)) rotate(e[g][1] == v ^ e[v][1] == u ? u : v);
  up(u);
}
inline void access(int u) {
  for (int w = 0; u; u = f[w = u])
    splay(u), add(a[u], -s[e[u][0]] - 1), e[u][1] = w, up(u);
}
inline void makeroot(int u, int v) {
  access(u), splay(u), add(a[u] = v, s[u]), swap(u);
}
void dfs(int u) {
  for (int& i = a[u]; i; i = b[i])
    if (c[i] != f[u]) f[c[i]] = u, dfs(c[i]);
}
int i, u, v, x, y;
char z[10];
int main() {
  for (scanf("%d%d", &n, &m), i = 1; i < n; i++)
    scanf("%d%d", &u, &v), b[i << 1] = a[u], c[a[u] = i << 1] = v,
                                  b[i << 1 | 1] = a[v],
                                  c[a[v] = i << 1 | 1] = u;
  for (dfs(n), memset(b + 1, 0, n << 2), t = m + n, memset(c + 1, 0, t << 2),
                                         i = 1;
       i <= n; i++)
    makeroot(i, i);
  for (i = 1; i <= m; i++)
    if (scanf("%s", z), *z == 'u')
      scanf("%d", &u), makeroot(u, n + i);
    else if (*z == 'w')
      scanf("%d", &u), splay(u), printf("%d\n", sum(a[u] - 1) + s[e[u][1]] + 1);
    else if (*z == 'c')
      scanf("%d%d", &u, &v), splay(u),
          x = s[e[u][1]], splay(v), y = s[e[v][1]],
          printf("%d\n", a[u] < a[v] || a[u] == a[v] && x < y ? u : v);
  return 0;
}
