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 std::pair;
const int MAX = 2e5 + 7;
void read_int(int &a) {
  char c = getchar();
  a = 0;
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') a = (a << 1) + (a << 3) - 48 + c, c = getchar();
  return;
}
int get_type() {
  char c = getchar();
  while (c != 'u' && c != 'w' && c != 'c') c = getchar();
  return c == 'u' ? 0 : (c == 'w' ? 1 : 2);
}
int n, m;
struct edge {
  int point, next;
} r[MAX << 1];
int last[MAX];
void link(int x, int y) {
  static int tot = 0;
  r[++tot] = (edge){y, last[x]};
  last[x] = tot;
  r[++tot] = (edge){x, last[y]};
  last[y] = tot;
  return;
}
int depth[MAX], f[MAX], size[MAX], son[MAX];
void pre_dfs1(int now) {
  size[now] = 1;
  depth[now] = depth[f[now]] + 1;
  for (int i = last[now]; i; i = r[i].next)
    if (r[i].point != f[now]) {
      f[r[i].point] = now;
      pre_dfs1(r[i].point);
      size[now] += size[r[i].point];
      if (size[r[i].point] > size[son[now]]) son[now] = r[i].point;
    }
  return;
}
int num[MAX], top[MAX];
void pre_dfs2(int now) {
  static int cnt = 0;
  num[now] = ++cnt;
  top[now] = (now == son[f[now]]) ? top[f[now]] : now;
  if (!son[now]) return;
  pre_dfs2(son[now]);
  for (int i = last[now]; i; i = r[i].next)
    if (r[i].point != son[now] && r[i].point != f[now]) pre_dfs2(r[i].point);
  return;
}
int tag[MAX << 2], have;
void add(int now, int left, int right, int x, int y, int val) {
  if (left == x && right == y) {
    tag[now] += val;
    return;
  }
  const int mid = (left + right) >> 1;
  if (y <= mid)
    add(now << 1, left, mid, x, y, val);
  else if (x > mid)
    add(now << 1 | 1, mid + 1, right, x, y, val);
  else
    add(now << 1, left, mid, x, mid, val),
        add(now << 1 | 1, mid + 1, right, mid + 1, y, val);
  return;
}
int ask(int now, int left, int right, int pos) {
  if (left == right) return tag[now];
  const int mid = (left + right) >> 1;
  if (pos <= mid) return ask(now << 1, left, mid, pos) + tag[now];
  return ask(now << 1 | 1, mid + 1, right, pos) + tag[now];
}
int sum[MAX << 2];
void add(int now, int left, int right, int pos, int val) {
  sum[now] += val;
  if (left == right) return;
  const int mid = (left + right) >> 1;
  if (pos <= mid)
    add(now << 1, left, mid, pos, val);
  else
    add(now << 1 | 1, mid + 1, right, pos, val);
  return;
}
int ask(int now, int left, int right, int x, int y) {
  if (left == x && right == y) return sum[now];
  const int mid = (left + right) >> 1;
  if (y <= mid) return ask(now << 1, left, mid, x, y);
  if (x > mid) return ask(now << 1 | 1, mid + 1, right, x, y);
  return ask(now << 1, left, mid, x, mid) +
         ask(now << 1 | 1, mid + 1, right, mid + 1, y);
}
int ival[MAX], deg[MAX];
std::priority_queue<int, std::vector<int>, std::greater<int>> q;
void calc_value() {
  for (int cur = 1; cur <= n; cur++)
    for (int i = last[cur]; i; i = r[i].next) ++deg[r[i].point];
  for (int cur = 1; cur <= n; cur++)
    if (deg[cur] == 1) q.push(cur);
  while (q.size()) {
    static int cnt = 0, cur;
    ival[num[cur = q.top()]] = ++cnt;
    q.pop();
    for (int i = last[cur]; i; i = r[i].next)
      if (--deg[r[i].point] == 1) q.push(r[i].point);
  }
  return;
}
int rt[MAX];
std::map<pair<int, int>, int> col[MAX];
void init() {
  calc_value();
  rt[0] = have = n;
  for (int i = 1; i <= n; i++) add(1, 1, n, i, n, 1);
  for (int i = 1; i <= n; i++)
    if (!son[i]) col[top[i]][pair<int, int>(num[top[i]], num[i])] = 0;
  return;
}
pair<int, int> get_range(int cur, int pos) {
  auto ans = col[cur].upper_bound(pair<int, int>(pos, n + 1));
  return ans == col[cur].end() ? col[cur].rbegin()->first : (--ans)->first;
}
void merge(int cur, int x, int y, int val) {
  pair<int, int> left = get_range(cur, x), right = get_range(cur, y);
  auto posl = col[cur].find(left), posr = col[cur].find(right);
  int typ_left = posl->second, typ_right = posr->second;
  auto point = posl;
  while (true) {
    if (!point->second) {
      have -= point->first.second - point->first.first + 1;
      int sl = std::max(x, point->first.first),
          tr = std::min(y, point->first.second);
      for (int i = sl; i <= tr; i++) add(1, 1, n, ival[i], n, -1);
    } else
      add(1, 1, m, point->second,
          -(point->first.second - point->first.first + 1));
    if (point++ == posr) break;
  }
  col[cur].erase(posl, ++posr);
  if (x > left.first) {
    col[cur][pair<int, int>(left.first, x - 1)] = typ_left;
    if (typ_left)
      add(1, 1, m, typ_left, x - left.first);
    else
      have += x - left.first;
  }
  if (y < right.second) {
    col[cur][pair<int, int>(y + 1, right.second)] = typ_right;
    if (typ_right)
      add(1, 1, m, typ_right, right.second - y);
    else
      have += right.second - y;
  }
  col[cur][pair<int, int>(x, y)] = val;
  add(1, 1, m, val, y - x + 1);
  return;
}
void up(int cur) {
  static int cnt = 0;
  rt[++cnt] = cur;
  int x = cur, y = rt[cnt - 1];
  while (top[x] != top[y]) {
    if (depth[top[x]] > depth[top[y]])
      merge(top[x], num[top[x]], num[x], cnt), x = f[top[x]];
    else
      merge(top[y], num[top[y]], num[y], cnt), y = f[top[y]];
  }
  if (depth[x] > depth[y])
    merge(top[x], num[y], num[x], cnt);
  else
    merge(top[y], num[x], num[y], cnt);
  return;
}
int get_col(int cur) { return col[top[cur]][get_range(top[cur], num[cur])]; }
int get_dis(int x, int y) {
  int ans = 0;
  while (top[x] != top[y])
    if (depth[top[x]] > depth[top[y]])
      ans += num[x] - num[top[x]] + 1, x = f[top[x]];
    else
      ans += num[y] - num[top[y]] + 1, y = f[top[y]];
  return ans + (num[x] > num[y] ? num[x] - num[y] : num[y] - num[x]) + 1;
}
int when(int cur) {
  auto range = col[top[cur]].find(get_range(top[cur], num[cur]));
  if (!range->second) return ask(1, 1, n, ival[num[cur]]);
  int ans = have;
  if (range->second > 1) ans += ask(1, 1, m, 1, range->second - 1);
  if (get_col(rt[range->second - 1]) == range->second)
    ans += get_dis(rt[range->second - 1], cur);
  else
    ++ans;
  return ans;
}
int main() {
  read_int(n);
  read_int(m);
  for (int i = 1, x, y; i < n; i++) read_int(x), read_int(y), link(x, y);
  pre_dfs1(1);
  pre_dfs2(1);
  init();
  for (int i = 1; i <= m; i++) {
    static int u, v;
    int type = get_type();
    if (type == 0)
      read_int(v), up(v);
    else if (type == 1)
      read_int(v), printf("%d\n", when(v));
    else
      read_int(v), read_int(u), printf("%d\n", when(v) < when(u) ? v : u);
  }
  return 0;
}