#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1, c = getchar();
  while (c < 48) c == '-' && (f = -1), c = getchar();
  while (c > 47) x = x * 10 + c - '0', c = getchar();
  return x * f;
}
const int MAXN = 400005;
std::vector<int> G[MAXN];
int fa[MAXN], size[MAXN], rev[MAXN];
int col[MAXN], tag[MAXN], st[MAXN];
int c[MAXN], ch[MAXN][2];
int n, q;
inline void addedge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}
inline void add(int x, int k) {
  while (x <= n + q) c[x] += k, x += x & -x;
}
inline int sum(int x) {
  int res = 0;
  while (x) res += c[x], x -= x & -x;
  return res;
}
inline void pushup(int x) { size[x] = size[ch[x][0]] + size[ch[x][1]] + 1; }
inline void pushr(int x) { swap(ch[x][0], ch[x][1]), rev[x] ^= 1; }
inline void pushc(int x, int k) { col[x] = tag[x] = k; }
inline void pushdown(int x) {
  if (rev[x]) {
    if (ch[x][0]) pushr(ch[x][0]);
    if (ch[x][1]) pushr(ch[x][1]);
    rev[x] = 0;
  }
  if (tag[x]) {
    if (ch[x][0]) pushc(ch[x][0], tag[x]);
    if (ch[x][1]) pushc(ch[x][1], tag[x]);
    tag[x] = 0;
  }
}
inline bool notroot(int x) { return ch[fa[x]][0] == x || ch[fa[x]][1] == x; }
inline void rotate(int x) {
  int y = fa[x], z = fa[y];
  int k = ch[y][1] == x, w = ch[x][k ^ 1];
  if (notroot(y)) ch[z][ch[z][1] == y] = x;
  fa[x] = z, fa[y] = x, fa[w] = y;
  ch[y][k] = w;
  ch[x][k ^ 1] = y;
  pushup(y);
}
inline void splay(int x) {
  int y = x, z = 0;
  st[++z] = y;
  while (notroot(y)) st[++z] = y = fa[y];
  while (z) pushdown(st[z--]);
  while (notroot(x)) {
    y = fa[x], z = fa[y];
    if (notroot(y)) rotate(ch[y][1] == x ^ ch[z][1] == y ? x : y);
    rotate(x);
  }
  pushup(x);
}
inline void access(int x, int k) {
  for (int y = 0; x; x = fa[x]) {
    splay(x);
    size[x] -= size[ch[x][1]];
    add(col[x], -size[x]);
    add(col[x] = tag[x] = k, size[x]);
    size[x] += size[ch[x][1] = y];
    y = x;
  }
}
inline void makeroot(int x, int k) { access(x, k), splay(x), pushr(x); }
inline int query(int x) { return splay(x), sum(col[x]) - size[ch[x][0]]; }
inline void dfs(int x, int p) {
  size[x] = 1;
  col[x] = x;
  add(x, 1);
  for (int y : G[x])
    if (y ^ p) fa[y] = x, dfs(y, x);
}
inline void compare(int x, int y) {
  printf("%d\n", query(x) < query(y) ? x : y);
}
int main(int argc, char const *argv[]) {
  n = read();
  q = read();
  for (int i = 1; i < n; ++i) addedge(read(), read());
  dfs(1, 0);
  for (int i = 1; i <= n; ++i) makeroot(i, i);
  for (int i = 1, opt, x; i <= q; ++i) {
    opt = read();
    x = read();
    if (opt == 754) makeroot(x, ++n);
    if (opt == 77192) printf("%d\n", query(x));
    if (opt == 57979613) compare(x, read());
  }
  return 0;
}
