#include <bits/stdc++.h>
using namespace std;
template <typename T>
void pfill(T* pst, const T* ped, T val) {
  for (; pst != ped; *(pst++) = val)
    ;
}
typedef class FenwickTree {
 public:
  int n;
  int* a;
  FenwickTree() {}
  FenwickTree(int n) : n(n) {
    a = new int[(n + 1)];
    pfill(a + 1, a + n + 1, 0);
  }
  void add(int idx, int val) {
    for (; idx <= n; idx += (idx & (-idx))) {
      a[idx] += val;
    }
  }
  int query(int idx) {
    int rt = 0;
    for (; idx; idx -= (idx & (-idx))) {
      rt += a[idx];
    }
    return rt;
  }
} FenwickTree;
typedef class SplayNode {
 public:
  int sz;
  bool rev;
  int c, tag_c;
  SplayNode* fa;
  SplayNode* ch[2];
  SplayNode() : sz(1), rev(false), tag_c(0), fa(NULL) { ch[0] = ch[1] = NULL; }
  void push_up() {
    sz = 1;
    if (ch[0]) sz += ch[0]->sz;
    if (ch[1]) sz += ch[1]->sz;
  }
  void modify_c(int _c) { c = tag_c = _c; }
  void reverse() {
    rev ^= 1;
    swap(ch[0], ch[1]);
  }
  void push_down() {
    if (rev) {
      rev = false;
      if (ch[0]) ch[0]->reverse();
      if (ch[1]) ch[1]->reverse();
    }
    if (tag_c) {
      if (ch[0]) ch[0]->modify_c(tag_c);
      if (ch[1]) ch[1]->modify_c(tag_c);
      tag_c = 0;
    }
  }
  bool isroot() { return !fa || (fa->ch[0] != this && fa->ch[1] != this); }
  int which() { return (isroot()) ? (-1) : (fa->ch[1] == this); }
} SplayNode;
typedef class LinkCutTree {
 public:
  SplayNode** _pool;
  SplayNode* pool;
  FenwickTree fen;
  LinkCutTree() {}
  LinkCutTree(int n, int q, int* fa, int* col) {
    _pool = new SplayNode*[(n + 1)];
    pool = new SplayNode[(n + 1)];
    fen = move(FenwickTree(n + q));
    for (int i = 1; i <= n; i++) {
      pool[i].c = col[i];
      pool[i].fa = ((fa[i]) ? (pool + fa[i]) : (NULL));
      fen.add(i, 1);
    }
  }
  void rotate(SplayNode* p) {
    SplayNode *fa = p->fa, *ffa = fa->fa;
    int d = p->which(), fd = ((ffa) ? (fa->which()) : (-1));
    fa->ch[d] = p->ch[d ^ 1];
    (p->ch[d ^ 1]) && (p->ch[d ^ 1]->fa = fa);
    p->ch[d ^ 1] = fa;
    fa->fa = p;
    p->fa = ffa;
    (~fd) && (ffa->ch[fd] = p);
    fa->push_up();
    p->push_up();
  }
  void splay(SplayNode* p) {
    SplayNode** tmp = _pool;
    for (SplayNode* q = p; *(++tmp) = q, !q->isroot(); q = q->fa)
      ;
    for (; tmp != _pool; (*tmp--)->push_down())
      ;
    for (; !p->isroot(); rotate(p)) {
      if (!p->fa->isroot()) {
        rotate((p->which() != p->fa->which()) ? (p) : (p->fa));
      }
    }
  }
  void access(SplayNode* p, int c) {
    SplayNode* q = NULL;
    int sum = 0;
    do {
      splay(p);
      p->ch[1] = NULL;
      p->push_up();
      fen.add(p->c, -p->sz);
      sum += p->sz;
      p->ch[1] = q;
      p->push_up();
      p->modify_c(c);
      q = p, p = p->fa;
    } while (p);
    fen.add(c, sum);
  }
  void make_root(SplayNode* p, int c) {
    access(p, c);
    splay(p);
    p->reverse();
    p->modify_c(c);
  }
  void modify(int u, int c) { make_root(pool + u, c); }
  int rank(int u) {
    SplayNode* p = pool + u;
    splay(p);
    int sum = fen.query(p->c - 1) + 1;
    return sum + ((p->ch[1]) ? (p->ch[1]->sz) : (0));
  }
} LinkCutTree;
int n, m;
int* fa;
int* deg;
vector<int>* g;
LinkCutTree lct;
inline void init() {
  scanf("%d%d", &n, &m);
  deg = new int[(n + 1)];
  g = new vector<int>[(n + 1)];
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
}
void dfs(int p, int _fa) {
  fa[p] = _fa;
  for (auto e : g[p]) {
    if (e ^ _fa) {
      dfs(e, p);
    }
  }
}
int* col;
inline void get_col() {
  col = new int[(n + 1)];
  priority_queue<int, vector<int>, greater<int> > que;
  for (int i = 1; i <= n; i++) {
    deg[i] = (signed)g[i].size();
    if (deg[i] == 1) {
      que.push(i);
    }
  }
  int cnt = 0;
  while (!que.empty()) {
    int e = que.top();
    que.pop();
    col[e] = ++cnt;
    for (auto eu : g[e]) {
      if (--deg[eu] == 1) {
        que.push(eu);
      }
    }
  }
}
inline void solve() {
  fa = new int[(n + 1)];
  dfs(n, 0);
  get_col();
  lct = LinkCutTree(n, m, fa, col);
  int mx = n, u, v;
  char str[10];
  while (m--) {
    scanf("%s%d", str, &u);
    if (str[0] == 'w') {
      int ans = lct.rank(u);
      printf("%d\n", ans);
    } else if (str[0] == 'c') {
      scanf("%d", &v);
      int ru = lct.rank(u), rv = lct.rank(v);
      printf("%d\n", (ru < rv) ? (u) : (v));
    } else if (str[0] == 'u') {
      lct.modify(u, ++mx);
    }
  }
}
int main() {
  init();
  solve();
  return 0;
}
