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 = 2e5 + 10;
int n, m;
int prt[maxn];
inline int Read() {
  register int ch, a;
  while (ch = getchar(), ch < '0' || ch > '9')
    ;
  a = ch ^ 48;
  while (ch = getchar(), ch >= '0' && ch <= '9') a = a * 10 + (ch ^ 48);
  return a;
}
int h[maxn], deg[maxn];
struct Edge {
  int to, nxt;
} e[maxn << 1];
int tot_Edge;
inline void AddEdge(int from, int to) {
  e[++tot_Edge] = (Edge){to, h[from]};
  h[from] = tot_Edge;
}
int TA[maxn];
void Top_Sort() {
  priority_queue<int, vector<int>, greater<int> > q;
  for (int i = 1; i <= n; i++)
    if (deg[i] == 1) q.push(i);
  while (!q.empty()) {
    int u = q.top();
    q.pop();
    TA[++TA[0]] = u;
    for (int i = h[u]; i; i = e[i].nxt) {
      int v = e[i].to;
      if ((--deg[v]) || v == n) {
        prt[u] = v;
        if (deg[v] == 1) q.push(v);
      }
    }
  }
}
namespace Treap {
struct Node {
  Node *lch, *rch, *prt;
  int size, Flp;
  inline void Flip() {
    swap(this->lch, this->rch);
    this->Flp ^= 1;
  }
  inline void Pushdown() {
    if (this->lch) this->lch->Flip();
    if (this->rch) this->rch->Flip();
    this->Flp = 0;
  }
  inline void MainTain() {
    this->size = (lch ? lch->size : 0) + (rch ? rch->size : 0) + 1;
  }
  inline int Pos() { return this->prt->lch == this; }
} node[maxn];
typedef pair<Node *, Node *> P;
Node *Root, *Trs;
inline P Split(Node *u, int K) {
  if (u == NULL) return P(NULL, NULL);
  if (u->Flp) u->Pushdown();
  P tmp;
  int LeftSize = u->lch ? u->lch->size : 0;
  if (K <= LeftSize) {
    if (u->lch) u->lch->prt = NULL;
    tmp = Split(u->lch, K);
    u->lch = tmp.second;
    if (tmp.second) tmp.second->prt = u;
    u->MainTain();
    tmp.second = u;
  } else {
    if (u->rch) u->rch->prt = NULL;
    tmp = Split(u->rch, K - LeftSize - 1);
    u->rch = tmp.first;
    if (tmp.first) tmp.first->prt = u;
    u->MainTain();
    tmp.first = u;
  }
  return tmp;
}
inline Node *Merge(Node *A, Node *B) {
  if (A == NULL) return B;
  if (B == NULL) return A;
  if (A->Flp) A->Pushdown();
  if (B->Flp) B->Pushdown();
  if (rand() % (A->size + B->size) < A->size) {
    if (A->rch) A->rch->prt = NULL;
    Node *p = Merge(A->rch, B);
    A->rch = p, p->prt = A;
    A->MainTain();
    return A;
  } else {
    if (B->lch) B->lch->prt = NULL;
    Node *p = Merge(A, B->lch);
    B->lch = p, p->prt = B;
    B->MainTain();
    return B;
  }
}
Node *tmp[23333];
int tot;
inline int Rank(int x) {
  Node *u = node + x;
  tot = 0;
  while (u) tmp[++tot] = u, u = u->prt;
  for (int i = tot; i >= 1; i--)
    if (tmp[i]->Flp) tmp[i]->Pushdown();
  int ret = (tmp[1]->lch ? tmp[1]->lch->size : 0) + 1;
  for (int i = 1; i < tot; i++)
    if (!tmp[i]->Pos())
      ret += (tmp[i]->prt->lch ? tmp[i]->prt->lch->size : 0) + 1;
  return ret;
}
inline void Cut(int u, int v) {
  int L = Rank(u), R = Rank(v);
  P A = Split(Root, R);
  P B = Split(A.first, L - 1);
  Trs = Merge(Trs, B.second);
  Root = Merge(B.first, A.second);
}
inline void Build() {
  for (int i = 1; i <= n; i++) {
    (node + TA[i])->size = 1;
    Root = Merge(Root, node + TA[i]);
  }
}
}  // namespace Treap
namespace LCT {
struct Node {
  Node *ch[2], *prt, *pprt;
  int Flp;
  inline void Flip() {
    swap(this->ch[0], this->ch[1]);
    this->Flp ^= 1;
  }
  inline void Pushdown() {
    if (this->ch[0]) this->ch[0]->Flip();
    if (this->ch[1]) this->ch[1]->Flip();
    this->Flp = 0;
  }
  inline int Pos() { return this->prt->ch[0] == this; }
} node[maxn];
inline void Rotate(Node *u, int k) {
  if (u->Flp) u->Pushdown();
  Node *tmp = u->ch[!k];
  if (tmp->Flp) tmp->Pushdown();
  if (!u->prt)
    tmp->pprt = u->pprt, u->pprt = NULL;
  else
    u->prt->ch[!u->Pos()] = tmp;
  tmp->prt = u->prt;
  u->ch[!k] = tmp->ch[k];
  if (tmp->ch[k]) tmp->ch[k]->prt = u;
  tmp->ch[k] = u;
  u->prt = tmp;
}
inline void Splay(Node *u, Node *Pos = NULL) {
  while (u->prt != Pos) {
    int k = u->Pos();
    if (u->Flp) u->Pushdown();
    if (u->prt->prt == Pos)
      Rotate(u->prt, k);
    else {
      int d = u->prt->Pos();
      Rotate(k == d ? u->prt->prt : u->prt, k);
      Rotate(u->prt, d);
    }
  }
}
inline void Clear(Node *u) {
  Splay(u);
  if (u->Flp) u->Pushdown();
  if (u->ch[1]) {
    u->ch[1]->pprt = u;
    u->ch[1]->prt = NULL;
    u->ch[1] = NULL;
  }
}
inline Node *Find_Root(Node *u) {
  Splay(u);
  while (u != NULL) {
    if (u->Flp) u->Pushdown();
    if (!u->ch[0]) return Splay(u), u;
    u = u->ch[0];
  }
  return NULL;
}
inline void Access(Node *u) {
  Clear(u);
  while (u->pprt != NULL) {
    Node *v = Find_Root(u);
    Treap::Cut(u - node, v - node);
    Splay(u);
    u->prt = u->pprt;
    Clear(u->prt);
    u->prt->ch[1] = u;
    u->pprt = NULL;
    u = u->prt;
  }
  Node *v = Find_Root(u);
  Treap::Cut(u - node, v - node);
}
inline void Make_Root(int x) {
  Node *u = node + x;
  Treap::Trs = NULL;
  Access(u), Splay(u), u->Flip();
  Treap::Trs->Flip();
  Treap::Root = Merge(Treap::Root, Treap::Trs);
}
inline void Build() {
  for (int i = n - 1; i >= 1; i--) (node + TA[i])->pprt = (node + prt[TA[i]]);
}
}  // namespace LCT
int main() {
  n = Read(), m = Read();
  for (int i = 1, u, v; i < n; i++) {
    u = Read(), v = Read();
    AddEdge(u, v), AddEdge(v, u);
    ++deg[u], ++deg[v];
  }
  Top_Sort();
  LCT::Build();
  Treap::Build();
  int tp, u, v;
  while (m--) {
    while (tp = getchar(), tp < 'a' || tp > 'z')
      ;
    if (tp == 'u')
      u = Read(), LCT::Make_Root(u);
    else if (tp == 'w')
      u = Read(), printf("%d\n", Treap::Rank(u));
    else {
      u = Read(), v = Read();
      printf("%d\n", (Treap::Rank(u) < Treap::Rank(v)) ? u : v);
    }
  }
  return 0;
}