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;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline long long rand(long long x, long long y) {
  return rng() % (y + 1 - x) + x;
}
string inline to_string(char c) {
  string second(1, c);
  return second;
}
template <typename T>
inline T gcd(T a, T b) {
  return a == 0 ? llabs(b) : gcd(b % a, a);
}
using ll = long long;
using ld = long double;
using pi = pair<ll, ll>;
using spi = pair<pi, ll>;
using dpi = pair<pi, pi>;
ll n, q, fw[(400006)];
vector<int> v[(400006) / 2];
void update(int x, ll nval) {
  for (; x < (400006); x += x & (-x)) fw[x] += nval;
}
ll sum(int x) {
  ll res = 0;
  for (; x; x -= x & (-x)) res += fw[x];
  return res;
}
int st[(400006)], co, p[(400006)], head[(400006)], heavy[(400006)],
    depth[(400006)], bck[(400006)], mx, now = 1;
map<pi, ll> mp[(400006) / 2];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> q;
  for (ll i = 0; i <= ll(n - 2); ++i) {
    ll a, b;
    cin >> a >> b;
    v[a].emplace_back(b), v[b].emplace_back(a);
  }
  function<ll(ll, ll)> dfs = [&](ll x, ll par) {
    p[x] = par;
    ll sz = 1, mx_sz = 0;
    for (auto i : v[x])
      if (i ^ par) {
        depth[i] = depth[x] + 1;
        ll c_sz = dfs(i, x);
        sz += c_sz;
        if (mx_sz < c_sz) mx_sz = c_sz, heavy[x] = i;
      }
    return sz;
  };
  function<void(ll, ll, ll)> hld = [&](ll x, ll p, ll h) {
    st[x] = co++, head[x] = h;
    if (heavy[x]) hld(heavy[x], x, h);
    for (auto i : v[x])
      if (i != p && i != heavy[x]) {
        hld(i, x, i);
      }
  };
  dfs(1, 1), hld(1, 1, 1);
  auto dist = [&](ll x, ll y) {
    ll ans = 0;
    for (; head[x] ^ head[y]; x = p[head[x]]) {
      if (depth[head[x]] < depth[head[y]]) swap(x, y);
      ans += st[x] - st[head[x]] + 1;
    }
    ans += max(st[x], st[y]) - min(st[x], st[y]) + 1;
    return ans;
  };
  auto re = [&](ll c, ll x) { update(c, -x); };
  auto proc = [&](ll x, ll a, ll b) {
    while (1) {
      auto it = mp[x].lower_bound(pi(a, 0));
      if (it == mp[x].end() || it->first.second > b) break;
      re(it->second, it->first.second - it->first.first + 1);
      mp[x].erase(it);
    }
    auto it = mp[x].lower_bound(pi(a, 0));
    if (it != mp[x].end() && it->first.first <= b) {
      assert(it->first.second > b);
      spi val = *it;
      re(val.second, b - val.first.first + 1);
      mp[x].erase(it);
      val.first.first = b + 1;
      mp[x].insert(val);
      it = mp[x].lower_bound(pi(a, 0));
    }
    if (it != mp[x].begin()) {
      --it;
      if (it->first.second >= a) {
        spi val = *it;
        re(val.second, val.first.second - a + 1);
        mp[x].erase(it);
        val.first.second = a - 1;
        mp[x].insert(val);
      }
    }
  };
  auto up = [&](ll node) {
    bck[++mx] = now;
    update(mx, dist(now, node));
    ll x = now, y = node;
    for (; head[x] ^ head[y]; x = p[head[x]]) {
      if (depth[head[x]] < depth[head[y]]) swap(x, y);
      proc(head[x], st[head[x]], st[x]);
      mp[head[x]][pi(st[head[x]], st[x])] = mx;
    }
    proc(head[x], min(st[x], st[y]), max(st[x], st[y]));
    mp[head[x]][pi(min(st[x], st[y]), max(st[x], st[y]))] = mx;
    now = node;
  };
  auto when = [&](ll x) {
    auto c = mp[head[x]].upper_bound(pi(st[x], ((long long)1e18)));
    assert(c != mp[head[x]].begin()), --c;
    return sum(c->second - 1) + dist(bck[c->second], x);
  };
  for (ll i = 1; i <= ll(n); ++i) up(i);
  while (q--) {
    string op;
    cin >> op;
    if (op == "up") {
      ll x;
      cin >> x;
      up(x);
    } else if (op == "when") {
      ll x;
      cin >> x;
      cout << when(x) << '\n';
    } else {
      ll x, y;
      cin >> x >> y;
      cout << (when(x) < when(y) ? x : y) << '\n';
    }
  }
}