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;
using ll = long long;
template <class t, class u>
void chmax(t& first, u second) {
  if (first < second) first = second;
}
template <class t, class u>
void chmin(t& first, u second) {
  if (first > second) first = second;
}
template <class t>
using vc = vector<t>;
template <class t>
using vvc = vc<vc<t>>;
using pi = pair<ll, ll>;
using vi = vc<ll>;
template <class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
  return os << "{" << p.first << "," << p.second << "}";
}
template <class t>
ostream& operator<<(ostream& os, const vc<t>& v) {
  os << "{";
  for (auto e : v) os << e << ",";
  return os << "}";
}
ll topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); }
ll topbit(ll t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); }
struct BIT {
  vi buf;
  ll s;
  BIT(ll n = 0) { init(n); }
  void init(ll n) { buf.assign(s = n, 0); }
  void add(ll i, ll v) {
    for (; i < s; i += (i + 1) & (-i - 1)) buf[i] += v;
  }
  ll get(ll i) {
    ll res = 0;
    for (; i >= 0; i -= (i + 1) & (-i - 1)) res += buf[i];
    return res;
  }
  ll sum(ll second, ll e) { return get(e - 1) - get(second - 1); }
  ll kth(ll k) {
    ll res = 0;
    for (ll i = topbit(s); i >= 0; i--) {
      ll w = res + (1 << i);
      if (w <= s && buf[w - 1] <= k) {
        k -= buf[w - 1];
        res = w;
      }
    }
    return res;
  }
};
template <class E>
struct HLD {
  vvc<E> g;
  ll n, r, cnt;
  vi sub, in, out, par, head, dep;
  ll dfs1(ll v, ll p, ll d) {
    par[v] = p;
    dep[v] = d;
    g[v].erase(remove(g[v].begin(), g[v].end(), p), g[v].end());
    for (auto& e : g[v]) {
      sub[v] += dfs1(e, v, d + 1);
      if (sub[g[v][0]] < sub[e]) swap(g[v][0], e);
    }
    return sub[v];
  }
  void dfs2(ll v, ll h) {
    in[v] = cnt++;
    head[v] = h;
    for (ll to : g[v]) dfs2(to, to == g[v][0] ? h : to);
    out[v] = cnt;
  }
  HLD(const vvc<E>& gg, ll rr)
      : g(gg),
        n(g.size()),
        r(rr),
        cnt(0),
        sub(n, 1),
        in(n),
        out(n),
        par(n, -1),
        head(n),
        dep(n) {
    dfs1(r, -1, 0);
    dfs2(r, r);
  }
  ll lca(ll first, ll second) {
    while (head[first] != head[second]) {
      if (dep[head[first]] > dep[head[second]]) swap(first, second);
      second = par[head[second]];
    }
    if (dep[first] > dep[second]) swap(first, second);
    return first;
  }
  void slv(ll q) {
    set<ll> ss;
    vi to(n), h(n), up(n);
    const auto add = [&](ll second, ll e, ll v, ll x) {
      to[second] = e;
      h[second] = v;
      up[second] = x;
      ss.insert(second);
    };
    {
      vi deg(n);
      priority_queue<ll, vi, greater<ll>> pq;
      for (ll i = ll(0); i < ll(n); i++) {
        deg[i] = g[i].size();
        if (deg[i] == 0) pq.push(i);
      }
      ll c = 0;
      vi idx(n, -1);
      while (pq.size()) {
        ll i = pq.top();
        pq.pop();
        idx[i] = c++;
        if (par[i] != -1 && --deg[par[i]] == 0) pq.push(par[i]);
      }
      for (ll i = ll(0); i < ll(n); i++) add(in[i], in[i] + 1, idx[i], 1);
    }
    ss.insert(n);
    const auto getitr = [&](ll i) { return prev(ss.upper_bound(i)); };
    const auto getval = [&](ll i) {
      auto itr = getitr(i);
      ll j = *itr;
      ll v = h[j] + (i - j) * up[j];
      return v;
    };
    const auto cut = [&](ll i) {
      auto itr = getitr(i);
      ll j = *itr;
      if (j == i) return;
      ll v = h[j] + (i - j) * up[j];
      add(i, to[j], v, up[j]);
      to[j] = i;
    };
    ll nx = n;
    vc<pi> del;
    const auto repl = [&](ll second, ll e, ll v) {
      if (e <= second) return;
      cut(second);
      cut(e);
      auto itr = ss.find(second);
      while (*itr < e) {
        ll i = *itr, z = h[i];
        if (up[i] < 0) z -= (to[i] - i - 1);
        del.emplace_back(z, i - to[i]);
        itr = ss.erase(itr);
      }
      add(second, e, v == 1 ? nx : nx + (e - second) - 1, v);
      nx += e - second;
    };
    const auto getpath = [&](ll first, ll second) {
      vc<pi> res;
      ll c = lca(first, second);
      while (1) {
        ll x = head[first];
        if (dep[x] > dep[c]) {
          res.emplace_back(in[first], in[x]);
        } else {
          res.emplace_back(in[first], in[c]);
          break;
        }
        first = par[x];
      }
      ll m = res.size();
      while (1) {
        ll x = head[second];
        if (dep[x] > dep[c]) {
          res.emplace_back(in[x], in[second]);
        } else {
          if (in[c] < in[second]) res.emplace_back(in[c] + 1, in[second]);
          break;
        }
        second = par[x];
      }
      reverse(res.begin() + m, res.end());
      return res;
    };
    ll last = n - 1;
    vi ans(q, -1);
    for (ll i = ll(0); i < ll(q); i++) {
      string ty;
      cin >> ty;
      if (ty == "up") {
        ll v;
        cin >> v;
        v--;
        if (last == v) continue;
        auto p = getpath(last, v);
        for (auto w : p) {
          ll first, second;
          tie(first, second) = w;
          if (first < second)
            repl(first, second + 1, 1);
          else
            repl(second, first + 1, -1);
        }
        last = v;
      } else if (ty == "when") {
        ll v;
        cin >> v;
        v--;
        ll x = getval(in[v]);
        ans[i] = x;
        del.emplace_back(x, i);
      } else {
        ll u, v;
        cin >> u >> v;
        u--;
        v--;
        void(0);
        void(0);
        ans[i] = getval(in[u]) < getval(in[v]) ? u : v;
      }
    }
    vi pos;
    for (auto d : del) pos.push_back(d.first);
    sort(pos.begin(), pos.end());
    pos.erase(unique(pos.begin(), pos.end()), pos.end());
    BIT bit(pos.size());
    for (auto d : del) {
      ll i = lower_bound(pos.begin(), pos.end(), d.first) - pos.begin();
      if (d.second < 0) {
        bit.add(i, d.second);
      } else {
        ans[d.second] += bit.get(i);
      }
    }
    for (auto v : ans)
      if (v != -1) cout << v + 1 << "\n";
  }
};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
  ll n, q;
  cin >> n >> q;
  vvc<ll> t(n);
  for (ll _ = ll(0); _ < ll(n - 1); _++) {
    ll first, second;
    cin >> first >> second;
    first--;
    second--;
    t[first].push_back(second);
    t[second].push_back(first);
  }
  HLD<ll>(t, n - 1).slv(q);
}