Problem: Lena is playing with matches. The natural question arising in the head of any child playing with matches is whether it's possible to set a tree on fire with a matches, or not.

Let's say, that the tree is a connected graph without cycles and the vertices are labeled with integers 1, 2, …, n. Also every vertex v has some integer priority p_v associated with it. All priorities are distinct.

It turns out, that if you set a tree on fire, it will burn to nothing. However, this process doesn't happen instantly. At the beginning, burns out the leaf (a vertex is called to be a leaf if it has only one adjacent vertex) of the tree of the minimum priority. Then burns out the leaf of the minimal priority of the remaining tree, and so on. This way, the vertices turn into the leaves and burn out until only one vertex remains. Then this vertex burns out as well.

Lena has prepared a tree of n vertices and every vertex in it has a priority p_v = v. Lena is very curious about burning out this tree. However, she understands, that if she will burn the tree now, then it will disappear completely. Lena is a kind girl and she will feel bad for the burned tree, so she wants to study the process of burning the tree only in her mind. Lena wants to process q queries, each of them is one of three following types:

  * "up v", assign the vertex v priority 1 + max\\{p_1, p_2, …, p_n\}; 
  * "when v", find the step at which the vertex v will burn out, if the tree would be set on fire now; 
  * "compare v u", find out which of the vertices v and u will burn out first, if the tree would be set on fire now. 



Notice, that if all priorities would be distinct, then after the "up" query they will stay distinct as well. Initially all priorities are distinct, hence during any (purely hypothetical of course) burning of the tree, all leafs would have distinct priorities.

Input

The first line contains two integers n and q (2 ≤ n ≤ 200 000, 1 ≤ q ≤ 200 000) — the number of vertices in the tree and the number of queries.

The i-th of the following n - 1 lines contains two integers v_i, u_i (1 ≤ v_i, u_i ≤ n), denoting the endpoints of the i-th edge.

Each of the remaining q lines contains a query of one of the following three types:

  * "up v" (1 ≤ v ≤ n) — change the priority of vertex v; 
  * "when v" (1 ≤ v ≤ n) — determine the step at which the vertex v will burn out; 
  * "compare v u" (1 ≤ v, u ≤ n, v ≠ u) — determine which of vertices v and u will burn out earlier in the current tree. 



It's guaranteed, that there is at least one query of type "when" or "compare".

Output

For every query of type "when" print one integer in range from 1 to n — the step at which the vertex v will burn out.

For every query of type "compare" print either v or u, depending on which one will burn out earlier.

Examples

Input


5 7
1 5
1 2
1 3
4 3
when 1
when 2
when 3
when 4
when 5
compare 2 3
compare 3 4


Output


4
1
3
2
5
2
4


Input


5 5
1 5
1 2
1 3
4 3
up 1
compare 2 4
compare 4 3
compare 3 1
compare 1 5


Output


2
4
3
5

Note

In the first example, the process of burning of the tree is illustrated on the following picture:

<image>

In particular, the vertices of the tree will burn out in the following order: [2, 4, 3, 1, 5].

In the second example, after applying the "up" operation, the order of vertices will change to: [2, 4, 3, 5, 1].

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int maxN = 202000;
class SplayData {
 public:
  int ch[2], fa, size, rev, key;
};
int n, Q, Fa[maxN], nodecnt;
vector<int> T[maxN];
priority_queue<int, vector<int>, greater<int> > Heap;
int B[maxN + maxN];
SplayData S[maxN];
void dfs_init(int u, int fa);
bool Isroot(int x);
void Update(int x);
void PushDown(int x);
void Reverse(int x);
void Rotate(int x);
void Splay(int x);
void Access(int x);
int Query(int u);
void Plus(int p, int k);
int Sum(int p);
int main() {
  scanf("%d%d", &n, &Q);
  for (int i = 1; i <= n; i++) S[i].key = i, S[i].size = 1;
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    T[u].push_back(v);
    T[v].push_back(u);
  }
  dfs_init(n, 0);
  nodecnt = n;
  for (int qi = 1; qi <= Q; qi++) {
    char ipt[10];
    scanf("%s", ipt);
    if (ipt[0] == 'u') {
      int u;
      scanf("%d", &u);
      ++nodecnt;
      Access(u);
      Splay(u);
      Reverse(u);
      S[u].key = nodecnt;
    }
    if (ipt[0] == 'w') {
      int u;
      scanf("%d", &u);
      printf("%d\n", Query(u));
    }
    if (ipt[0] == 'c') {
      int u, v, m1, m2;
      scanf("%d%d", &u, &v);
      printf("%d\n", Query(u) < Query(v) ? u : v);
    }
  }
  return 0;
}
void dfs_init(int u, int fa) {
  S[u].fa = fa;
  S[u].key = u;
  for (int i = 0; i < T[u].size(); i++) {
    int v = T[u][i];
    if (v == fa) continue;
    dfs_init(v, u);
    if (S[v].key > S[u].key) {
      S[u].key = S[v].key;
      S[u].ch[1] = v;
      S[u].size = S[v].size + 1;
    }
  }
  Plus(S[u].key, 1);
  return;
}
bool Isroot(int x) {
  int fa = S[x].fa;
  if (S[fa].ch[0] == x || S[fa].ch[1] == x) return 0;
  return 1;
}
void Update(int x) {
  S[x].size = 1;
  if (S[x].ch[0]) S[x].size += S[S[x].ch[0]].size;
  if (S[x].ch[1]) S[x].size += S[S[x].ch[1]].size;
  return;
}
void Reverse(int x) {
  S[x].rev ^= 1;
  swap(S[x].ch[0], S[x].ch[1]);
  return;
}
void PushDown(int x) {
  if (S[x].rev) {
    if (S[x].ch[0]) Reverse(S[x].ch[0]);
    if (S[x].ch[1]) Reverse(S[x].ch[1]);
    S[x].rev = 0;
  }
  if (S[x].ch[0]) S[S[x].ch[0]].key = S[x].key;
  if (S[x].ch[1]) S[S[x].ch[1]].key = S[x].key;
  return;
}
void Rotate(int x) {
  int y = S[x].fa, z = S[y].fa, sx = (x == S[y].ch[1]), sy = (y == S[z].ch[1]);
  S[x].fa = z;
  if (Isroot(y) == 0) S[z].ch[sy] = x;
  S[y].ch[sx] = S[x].ch[sx ^ 1];
  if (S[x].ch[sx ^ 1]) S[S[x].ch[sx ^ 1]].fa = y;
  S[x].ch[sx ^ 1] = y;
  S[y].fa = x;
  Update(y);
  return;
}
void Splay(int x) {
  static int ST[maxN];
  int now = x, top = 1;
  ST[1] = x;
  while (!Isroot(now)) ST[++top] = now = S[now].fa;
  while (top) PushDown(ST[top--]);
  while (!Isroot(x)) {
    int y = S[x].fa, z = S[y].fa;
    if (!Isroot(y))
      ((x == S[y].ch[0]) ^ (y == S[z].ch[0])) ? Rotate(x) : Rotate(y);
    Rotate(x);
  }
  Update(x);
  return;
}
void Access(int x) {
  int lstx = 0;
  while (x) {
    Splay(x);
    S[x].ch[1] = 0;
    Update(x);
    Plus(S[x].key, -S[x].size);
    S[x].ch[1] = lstx;
    Update(x);
    lstx = x;
    x = S[x].fa;
  }
  Splay(lstx);
  Plus(nodecnt, S[lstx].size);
  return;
}
int Query(int x) {
  Splay(x);
  return Sum(S[x].key) - S[S[x].ch[0]].size;
}
void Plus(int p, int k) {
  while (p <= n + Q) {
    B[p] += k;
    p += (p) & (-p);
  }
  return;
}
int Sum(int p) {
  int ret = 0;
  while (p) {
    ret += B[p];
    p -= (p) & (-p);
  }
  return ret;
}