#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int n, q;
struct skr {
  int to, nxt;
} a[maxn << 1];
int head[maxn], cnt;
inline void add_skr(int x, int to) {
  a[++cnt].nxt = head[x];
  a[cnt].to = to;
  head[x] = cnt;
  a[++cnt].nxt = head[to];
  a[cnt].to = x;
  head[to] = cnt;
}
struct BIT {
  int v[maxn << 1];
  inline void add(int pos, int x) {
    for (; pos <= n + q; pos += (pos & -pos)) v[pos] += x;
  }
  inline int query(int pos) {
    int ans = 0;
    for (; pos; pos -= (pos & -pos)) ans += v[pos];
    return ans;
  }
} ft;
int fa[maxn];
int ch[maxn][2];
int sz[maxn];
int col[maxn];
int tag[maxn];
inline void dfs(int x) {
  col[x] = x;
  sz[x] = 1;
  for (int i = head[x]; i; i = a[i].nxt) {
    register int to = a[i].to;
    if (to != fa[x]) {
      fa[to] = x;
      dfs(to);
      if (col[to] > col[x]) {
        col[x] = col[to];
        ch[x][1] = to;
        sz[x] = sz[to] + 1;
      }
    }
  }
  ft.add(col[x], 1);
}
inline bool nroot(int x) { return ch[fa[x]][0] == x || ch[fa[x]][1] == x; }
inline void upd(int x) { sz[x] = sz[ch[x][0]] + sz[ch[x][1]] + 1; }
inline void rev(int x) {
  tag[x] ^= 1;
  swap(ch[x][0], ch[x][1]);
}
inline void push_down(int x) {
  if (tag[x]) {
    tag[x] = 0;
    if (ch[x][0]) rev(ch[x][0]);
    if (ch[x][1]) rev(ch[x][1]);
  }
  if (ch[x][0]) col[ch[x][0]] = col[x];
  if (ch[x][1]) col[ch[x][1]] = col[x];
}
inline void rotate(int x) {
  int y = fa[x], z = fa[y];
  int d = ch[y][1] == x, k = ch[x][!d];
  if (nroot(y)) ch[z][ch[z][1] == y] = x;
  fa[x] = z;
  ch[x][!d] = y;
  fa[y] = x;
  ch[y][d] = k;
  if (k) fa[k] = y;
  upd(y);
  upd(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(((ch[z][1] == y) ^ (ch[y][1] == x)) ? x : y);
    }
    rotate(x);
  }
}
int idx;
inline void access(int x) {
  for (int y = 0; x; x = fa[y = x]) {
    splay(x);
    ch[x][1] = 0;
    upd(x);
    ft.add(col[x], -sz[x]);
    ft.add(idx, sz[x]);
    ch[x][1] = y;
    upd(x);
  }
}
inline void make_root(int x) {
  idx++;
  access(x);
  splay(x);
  rev(x);
  col[x] = idx;
}
char opt[23];
inline int query(int x) {
  splay(x);
  return ft.query(col[x]) - sz[ch[x][0]];
}
int main() {
  scanf("%d%d", &n, &q);
  idx = n;
  for (int i = 1, x, y; i < n; ++i) {
    scanf("%d%d", &x, &y);
    add_skr(x, y);
  }
  dfs(n);
  int x, y;
  for (int i = 1; i <= q; ++i) {
    scanf("%s", opt);
    scanf("%d", &y);
    if (opt[0] == 'u') {
      make_root(y);
    } else if (opt[0] == 'w') {
      printf("%d\n", query(y));
    } else {
      scanf("%d", &x);
      int ans1 = query(x);
      int ans2 = query(y);
      printf("%d\n", ans1 < ans2 ? x : y);
    }
  }
  return 0;
}
