#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, m, t, tot, head[N], deg[N];
char typ[10];
struct edge {
  int next, to;
} e[N * 2];
void add(int from, int to) {
  e[++tot] = (edge){head[from], to};
  head[from] = tot;
}
struct BIT {
  int c[N * 2];
  void add(int x, int v) {
    if (!x) return;
    for (int i = x; i < N * 2; i += i & -i) c[i] += v;
  }
  int query(int x) {
    int ans = 0;
    for (int i = x; i; i -= i & -i) ans += c[i];
    return ans;
  }
} bit;
struct LCT {
  int fa[N], ch[N][2], siz[N], col[N];
  bool rev[N];
  bool pos(int x) { return x == ch[fa[x]][1]; }
  bool notrt(int x) { return x == ch[fa[x]][0] || x == ch[fa[x]][1]; }
  void pushup(int x) { siz[x] = siz[ch[x][0]] + siz[ch[x][1]] + 1; }
  void pushdown(int x) {
    if (rev[x]) {
      int lc = ch[x][0], rc = ch[x][1];
      if (lc) swap(ch[lc][0], ch[lc][1]), rev[lc] ^= 1;
      if (rc) swap(ch[rc][0], ch[rc][1]), rev[rc] ^= 1;
      rev[x] = 0;
    }
    if (ch[x][0]) col[ch[x][0]] = col[x];
    if (ch[x][1]) col[ch[x][1]] = col[x];
  }
  void rotate(int x) {
    int y = fa[x], z = fa[y], k = pos(x), c = ch[x][k ^ 1];
    if (notrt(y)) ch[z][pos(y)] = x;
    ch[x][k ^ 1] = y;
    ch[y][k] = c;
    if (c) fa[c] = y;
    fa[y] = x;
    fa[x] = z;
    pushup(y);
    pushup(x);
  }
  void splay(int x) {
    stack<int> st;
    st.push(x);
    for (int i = x; notrt(i); i = fa[i]) st.push(fa[i]);
    for (; st.size(); st.pop()) pushdown(st.top());
    for (; notrt(x); rotate(x))
      if (notrt(fa[x])) rotate(pos(x) == pos(fa[x]) ? fa[x] : x);
  }
  void access(int x) {
    int y = 0;
    for (; x; y = x, x = fa[x]) {
      splay(x);
      bit.add(col[x], -siz[x] + siz[ch[x][1]]);
      if (ch[x][1]) col[ch[x][1]] = col[x];
      ch[x][1] = y;
      pushup(x);
    }
    col[y] = t;
    bit.add(t, siz[y]);
  }
  void makert(int x) {
    t++;
    access(x);
    splay(x);
    swap(ch[x][0], ch[x][1]);
    rev[x] ^= 1;
  }
  int query(int x) {
    splay(x);
    return bit.query(col[x] - 1) + siz[ch[x][1]] + 1;
  }
} lct;
void dfs(int x, int fa) {
  lct.fa[x] = fa;
  lct.siz[x] = 1;
  for (int i = head[x]; ~i; i = e[i].next) {
    int v = e[i].to;
    if (v != fa) dfs(v, x);
  }
}
void topsort() {
  priority_queue<int> q;
  for (int i = 1; i <= n; i++)
    if (deg[i] == 1) q.push(-i);
  while (q.size()) {
    int u = -q.top();
    q.pop();
    lct.makert(u);
    for (int i = head[u]; ~i; i = e[i].next) {
      int v = e[i].to;
      if (deg[v] > 1) {
        deg[v]--;
        if (deg[v] == 1) q.push(-v);
      }
    }
  }
}
int main() {
  memset(head, -1, sizeof(head));
  scanf("%d%d", &n, &m);
  for (int i = 1, x, y; i < n; i++) {
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
    deg[x]++;
    deg[y]++;
  }
  dfs(1, 0);
  topsort();
  while (m--) {
    scanf("%s", typ);
    if (typ[0] == 'u') {
      int x;
      scanf("%d", &x);
      lct.makert(x);
    }
    if (typ[0] == 'w') {
      int x;
      scanf("%d", &x);
      printf("%d\n", lct.query(x));
    }
    if (typ[0] == 'c') {
      int x, y;
      scanf("%d%d", &x, &y);
      printf("%d\n", lct.query(x) < lct.query(y) ? x : y);
    }
  }
  return 0;
}
