#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m;
char op[11];
namespace BIT {
int tree[410000], n;
void add(int x, int y) {
  for (; x <= n; x += x & -x) tree[x] += y;
}
int query(int x) {
  int res = 0;
  for (; x; x -= x & -x) res += tree[x];
  return res;
}
}  // namespace BIT
int cur;
namespace LCT {
int ch[210000][2], fa[210000], rev[210000], siz[210000], val[210000];
int top, s[410000];
bool dir(int x) { return ch[(fa[x])][1] == x; }
inline bool nroot(int x) { return ch[(fa[x])][0] == x || ch[(fa[x])][1] == x; }
inline void pushup(int x) { siz[x] = siz[ch[(x)][0]] + siz[ch[(x)][1]] + 1; }
inline void pushdown(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 (ch[(x)][0]) val[ch[(x)][0]] = val[x];
  if (ch[(x)][1]) val[ch[(x)][1]] = val[x];
}
void rotate(int x) {
  int y = fa[x], z = fa[y], k = dir(x);
  fa[x] = z;
  if (nroot(y)) ch[z][dir(y)] = x;
  ch[y][k] = ch[x][k ^ 1];
  fa[ch[x][k ^ 1]] = y;
  ch[x][k ^ 1] = y;
  fa[y] = x;
  pushup(y);
  pushup(x);
}
void splay(int x) {
  top = 1;
  s[1] = x;
  for (int y = x; nroot(y); y = fa[y]) s[++top] = fa[y];
  while (top) pushdown(s[top--]);
  for (; nroot(x); rotate(x))
    if (nroot(fa[x])) rotate(dir(x) == dir(fa[x]) ? fa[x] : x);
}
inline void access(int x) {
  for (int y = 0; x; y = x, x = fa[x]) {
    splay(x);
    ch[(x)][1] = 0;
    pushup(x);
    BIT::add(val[x], -siz[x]);
    BIT::add(cur, siz[x]);
    ch[(x)][1] = y;
    pushup(x);
  }
}
inline void makeroot(int x) {
  ++cur;
  access(x);
  splay(x);
  rev[x] ^= 1;
  val[x] = cur;
}
inline int query(int x) {
  splay(x);
  return BIT::query(val[x]) - siz[ch[(x)][0]];
}
}  // namespace LCT
using namespace LCT;
int edgenum, vet[410000], Next[410000], Head[210000];
void addedge(int x, int y) {
  vet[++edgenum] = y;
  Next[edgenum] = Head[x];
  Head[x] = edgenum;
}
void dfs(int u) {
  siz[u] = 1;
  val[u] = u;
  for (int e = Head[u]; e; e = Next[e]) {
    int v = vet[e];
    if (v == fa[u]) continue;
    fa[v] = u;
    dfs(v);
    if (val[v] > val[u]) {
      val[u] = val[v];
      siz[u] = siz[v] + 1;
      ch[(u)][1] = v;
    }
  }
  BIT::add(val[u], 1);
}
int main() {
  scanf("%d%d", &n, &m);
  cur = n;
  BIT::n = n + m;
  int x, y;
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    addedge(x, y);
    addedge(y, x);
  }
  dfs(n);
  while (m--) {
    scanf("%s", op);
    if (op[0] == 'u') {
      scanf("%d", &x);
      makeroot(x);
    } else if (op[0] == 'w') {
      scanf("%d", &x);
      printf("%d\n", query(x));
    } else {
      scanf("%d%d", &x, &y);
      printf("%d\n", (query(x) < query(y) ? x : y));
    }
  }
  return 0;
}
