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;
vector<int> vc[650000];
struct Node {
  int col, slazy;
  int sz;
  int p, pp, l, r;
};
Node tree[650000];
int P[650000][20], tree2[650000];
int st[650000], en[650000], shes[650000];
void update(int idx, int x) {
  if (idx == 0) return;
  while (idx < 650000) {
    tree2[idx] += x;
    idx += idx & (-idx);
  }
}
int query(int idx) {
  int sum = 0;
  while (idx > 0) {
    sum += tree2[idx];
    idx -= idx & (-idx);
  }
  return sum;
}
void update(int x) { tree[x].sz = tree[tree[x].r].sz + tree[tree[x].l].sz + 1; }
void rotr(int x) {
  int y, z;
  y = tree[x].p, z = tree[y].p;
  if ((tree[y].l = tree[x].r)) tree[tree[y].l].p = y;
  tree[x].r = y, tree[y].p = x;
  if ((tree[x].p = z)) {
    if (y == tree[z].l)
      tree[z].l = x;
    else
      tree[z].r = x;
  }
  tree[x].pp = tree[y].pp;
  tree[y].pp = 0;
  update(y);
}
void rotl(int x) {
  int y, z;
  y = tree[x].p, z = tree[y].p;
  if ((tree[y].r = tree[x].l)) tree[tree[y].r].p = y;
  tree[x].l = y, tree[y].p = x;
  if ((tree[x].p = z)) {
    if (y == tree[z].l)
      tree[z].l = x;
    else
      tree[z].r = x;
  }
  tree[x].pp = tree[y].pp;
  tree[y].pp = 0;
  update(y);
}
void up(int x) {
  if (tree[x].p) up(tree[x].p);
  if (tree[x].slazy) {
    tree[x].col = max(tree[x].col, tree[x].slazy);
    tree[tree[x].l].slazy = max(tree[x].slazy, tree[tree[x].l].slazy);
    tree[tree[x].r].slazy = max(tree[x].slazy, tree[tree[x].r].slazy);
    tree[x].slazy = 0;
  }
}
void splay(int x) {
  int y, z;
  up(x);
  while (tree[x].p) {
    y = tree[x].p;
    if (tree[y].p == 0) {
      if (x == tree[y].l)
        rotr(x);
      else
        rotl(x);
    } else {
      z = tree[y].p;
      if (y == tree[z].l) {
        if (x == tree[y].l)
          rotr(y), rotr(x);
        else
          rotl(x), rotr(x);
      } else {
        if (x == tree[y].r)
          rotl(y), rotl(x);
        else
          rotr(x), rotl(x);
      }
    }
  }
  update(x);
}
int cnt;
int access(int x, int c, int ff) {
  splay(x);
  int g = tree[x].col;
  int ck = 0;
  if (tree[x].r) {
    tree[tree[x].r].pp = x;
    tree[tree[x].r].p = 0;
    tree[x].r = 0;
    update(x);
  }
  if (c && x != ff) update(g, -tree[x].sz);
  if (c && x == ff) {
    assert(tree[x].sz == 1);
    assert(g == cnt);
    ck = 1;
  }
  int last = x;
  while (tree[x].pp) {
    int y = tree[x].pp;
    last = y;
    splay(y);
    if (tree[y].r) {
      tree[tree[y].r].pp = y;
      tree[tree[y].r].p = 0;
      tree[y].r = 0;
      update(y);
    }
    int g = tree[y].col;
    if (c && y == ff) {
      ck = 1;
      assert(g == cnt);
      assert(tree[y].sz == 1);
    }
    if (c && y != ff) update(g, -tree[y].sz);
    tree[y].r = x;
    tree[x].p = y;
    tree[x].pp = 0;
    update(y);
    splay(x);
  }
  if (ff != -1) assert(ck == 1);
  return last;
}
int t, L[650000];
void dfs(int v, int par, int lev) {
  st[v] = ++t;
  P[v][0] = par;
  L[v] = lev;
  tree[v].sz = 1;
  tree[v].pp = max(par, 0);
  for (int i = 0; i < vc[v].size(); i++) {
    int w = vc[v][i];
    if (w == par) continue;
    dfs(w, v, lev + 1);
  }
  en[v] = t;
}
int qq(int x, int s, int e) {
  if (st[x] <= s && en[x] >= e) return x;
  for (int j = 18; j >= 0; j--) {
    int g = P[x][j];
    if (g == -1) continue;
    if (st[g] <= s && en[g] >= e) continue;
    x = g;
  }
  return P[x][0];
}
int lca_query(int l, int k) {
  return qq(l, min(st[l], st[k]), max(st[l], st[k]));
}
void addup(int last, int l, int cnt) {
  int glca = lca_query(last, l);
  splay(glca);
  tree[tree[glca].l].pp = tree[glca].pp;
  tree[tree[glca].l].p = 0;
  tree[glca].l = 0;
  tree[tree[glca].r].p = 0;
  tree[tree[glca].r].pp = glca;
  tree[glca].r = 0;
  update(glca);
  tree[glca].pp = 0;
  access(last, 1, -1);
  tree[last].slazy = cnt;
  access(l, 1, glca);
  tree[l].slazy = cnt;
  update(cnt, L[last] + L[l] - 2 * L[glca] + 1);
  tree[l].pp = max(P[glca][0], 0);
}
int preans[650000], n;
int when(int l) {
  splay(l);
  int ans = query(tree[l].col - 1);
  int g = tree[l].col;
  if (g <= n) {
    return ans + 1;
  }
  int c = lca_query(shes[g], l);
  ans += L[l] + L[shes[g]] - 2 * L[c] + 1;
  return ans;
}
int in[650000];
int prep(int n) {
  int last = 0;
  priority_queue<int> q;
  for (int i = 1; i <= n; i++) {
    in[i] = vc[i].size();
    if (in[i] == 1) q.push(-i);
  }
  while (!q.empty()) {
    int v = -q.top();
    q.pop();
    cnt++;
    for (int i = 0; i < vc[v].size(); i++) {
      int w = vc[v][i];
      in[w] -= 1;
      if (in[w] == 1) q.push(-w);
    }
    if (1) {
      shes[cnt] = v;
      preans[v] = cnt;
      last = v;
      tree[v].col = cnt;
      update(cnt, 1);
      continue;
    }
  }
  return last;
}
int main() {
  int i, j, k, l, m, last;
  memset(P, -1, sizeof P);
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &l, &k);
    vc[l].push_back(k);
    vc[k].push_back(l);
  }
  dfs(1, -1, 1);
  for (int j = 1; j <= 18; j++) {
    for (int i = 1; i <= n; i++) {
      if (P[i][j - 1] == -1) continue;
      P[i][j] = P[P[i][j - 1]][j - 1];
    }
  }
  last = prep(n);
  assert(last == n);
  last = n;
  char str[9];
  for (int i = 1; i <= m; i++) {
    scanf("%s", str);
    if (str[0] == 'u') {
      scanf("%d", &l);
      if (last == l) continue;
      cnt++;
      addup(last, l, cnt);
      shes[cnt] = last;
      last = l;
      continue;
    }
    if (str[0] == 'w') {
      scanf("%d", &l);
      int ans = when(l);
      printf("%d\n", ans);
      continue;
    }
    scanf("%d%d", &l, &k);
    if (when(l) < when(k))
      printf("%d\n", l);
    else
      printf("%d\n", k);
  }
}