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>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int maxn = 2e5 + 10, mod = 1e9 + 7;
const long long inf = 1e18;
vector<int> v[maxn];
int SZ[maxn], st[maxn], who[maxn], tp[maxn], h[maxn], start;
void dfssz(int u, int par = -1) {
  SZ[u] = 1;
  for (int y : v[u]) {
    if (y != par) dfssz(y, u), SZ[u] += SZ[y];
  }
}
void prep(int u, int par = -1, bool is = 1) {
  sort(v[u].begin(), v[u].end(), [&](int a, int b) { return SZ[a] < SZ[b]; });
  if (par == -1) v[u].push_back(-1);
  st[u] = start;
  who[start] = u;
  h[u] = par == -1 ? 0 : h[par] + 1;
  start++;
  tp[u] = is ? u : tp[par];
  if (int((v[u]).size()) > 1) prep(v[u][int((v[u]).size()) - 2], u, 0);
  for (int i = 0; i < int((v[u]).size()) - 2; i++) {
    prep(v[u][i], u, 1);
  }
}
template <long long Max, int Mxnode>
struct Segment {
  int nxt[Mxnode], Lz[Mxnode], Val[Mxnode], C = 1;
  void add(long long f, long long s, int x, long long l = 0, long long r = Max,
           int id = 0) {
    if (s <= l || r <= f) return;
    if (f <= l && r <= s) {
      Lz[id] += x;
      Val[id] += (r - l) * x;
      return;
    }
    if (nxt[id] == 0) nxt[id] = C, C += 2;
    long long mid = (l + r) >> 1;
    add(f, s, x, l, mid, nxt[id]), add(f, s, x, mid, r, nxt[id] + 1);
    Val[id] = Val[nxt[id]] + Val[nxt[id] + 1] + (r - l) * Lz[id];
  }
  int ask(long long f, long long s, long long l = 0, long long r = Max,
          int id = 0, int nw = 0) {
    if (s <= l || r <= f) return 0;
    if (f <= l && r <= s) return Val[id] + nw * (r - l);
    if (nxt[id] == 0) {
      nw += Lz[id];
      return nw * (min(r, s) - max(l, f));
    }
    long long mid = (l + r) >> 1;
    return ask(f, s, l, mid, nxt[id], nw + Lz[id]) +
           ask(f, s, mid, r, nxt[id] + 1, nw + Lz[id]);
  }
};
Segment<40000200000, 22345678> seg;
set<pair<pair<int, int>, pair<long long, long long> > > Set;
void add(int l, int r, long long f, long long s) {
  auto it = --Set.lower_bound((
      pair<pair<int, int>, pair<long long, long long> >){{l, 1e9}, {1e9, 1e9}});
  if ((it->first.first) != l) {
    auto x = *it;
    Set.erase(it);
    bool bl = x.second.first < x.second.second;
    long long num = x.second.first + (bl ? 1 : -1) * (l - x.first.first);
    Set.insert({{x.first.first, l - 1}, {x.second.first, num + (bl ? -1 : 1)}});
    Set.insert({{l, x.first.second}, {num, x.second.second}});
  }
  it = --Set.lower_bound((pair<pair<int, int>, pair<long long, long long> >){
      {r, 1e9}, {1e9, 1e9}});
  if ((it->first.second) != r) {
    auto x = *it;
    Set.erase(it);
    bool bl = x.second.first < x.second.second;
    long long num = x.second.second - (bl ? 1 : -1) * (x.first.second - r);
    Set.insert({{x.first.first, r}, {x.second.first, num}});
    Set.insert(
        {{r + 1, x.first.second}, {num + (bl ? 1 : -1), x.second.second}});
  }
  it = --Set.lower_bound((pair<pair<int, int>, pair<long long, long long> >){
      {l, 1e9}, {1e9, 1e9}});
  while (it != Set.end() && (it->first.first) != r + 1) {
    long long A = it->second.first, B = it->second.second;
    if (A > B) swap(A, B);
    seg.add(A, B + 1, -1);
    ++it, Set.erase(prev(it));
  }
  Set.insert({{l, r}, {f, s}});
  if (f > s) swap(f, s);
  seg.add(f, s + 1, 1);
}
int ask(int pos) {
  auto x =
      *(--Set.lower_bound((pair<pair<int, int>, pair<long long, long long> >){
          {pos, 1e9}, {1e9, 1e9}}));
  bool bl = x.second.first < x.second.second;
  long long num = x.second.first + (bl ? 1 : -1) * (pos - x.first.first);
  return seg.ask(0, num) + 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    v[a].push_back(b), v[b].push_back(a);
  }
  priority_queue<int, vector<int>, greater<int> > pq;
  int dg[maxn], ans[maxn];
  for (int i = 0; i < n; i++) {
    dg[i] = int((v[i]).size());
    if (dg[i] == 1) pq.push(i);
  }
  long long C = 0;
  while (int((pq).size())) {
    int u = pq.top();
    pq.pop();
    dg[u] = 0;
    for (int y : v[u]) {
      if (--dg[y] == 1) pq.push(y);
    }
    ans[u] = C, C++;
  }
  int lst = n - 1;
  dfssz(0);
  prep(0);
  seg.add(0, n, 1);
  for (int i = 0; i < n; i++) {
    Set.insert({{st[i], st[i]}, {ans[i], ans[i]}});
  }
  while (q--) {
    string task;
    cin >> task;
    if (task == "up") {
      int u;
      cin >> u;
      --u;
      long long vA = C, vB = C + n - 1;
      C += n;
      int A = lst, B = u;
      lst = u;
      while (tp[A] != tp[B]) {
        if (h[tp[A]] < h[tp[B]]) swap(A, B), swap(vA, vB);
        int cnt = st[A] - st[tp[A]] + 1;
        if (vA < vB)
          add(st[tp[A]], st[A], vA + cnt - 1, vA), vA += cnt;
        else
          add(st[tp[A]], st[A], vA - cnt + 1, vA), vA -= cnt;
        A = v[tp[A]].back();
      }
      if (h[A] < h[B]) swap(A, B), swap(vA, vB);
      int cnt = st[A] - st[B] + 1;
      if (vA < vB)
        add(st[B], st[A], vA + cnt - 1, vA);
      else
        add(st[B], st[A], vA - cnt + 1, vA);
    }
    if (task == "when") {
      int a;
      cin >> a;
      --a;
      cout << ask(st[a]) << "\n";
    }
    if (task == "compare") {
      int a, b;
      cin >> a >> b;
      --a, --b;
      cout << (ask(st[a]) < ask(st[b]) ? a + 1 : b + 1) << "\n";
    }
  }
  return 0;
}