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 JAVA):

Solution:
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

public class F {

	int[][] g;

	Node1[] nodesLC;
	Node2 root;

	void splay1(Node1 v, boolean swapBig) {
		// ok so this is splay
		// BUT ALSO there is a field called "big"
		// which we need to "move" from the current root
		// to this node

		if (v.isRoot()) {
			v.push();
			return;
		}

		if (swapBig) {

			Node1 root = v;
			while (!root.isRoot()) {
				root = root.up;
			}
			v.big = root.big;
			root.big = null;
			v.big.path = v;

		}

		do {
			Node1 u = v.up;
			Node1 t = u.up;
			boolean uRoot = u.isRoot();
			if (!uRoot) {
				t.push();
			}
			u.push();
			v.push();
			if (!uRoot) {
				((t.l == u) == (u.l == v) ? u : v).rotate();
			}
			v.rotate();
		} while (!v.isRoot());
		v.update();
	}

	void splay2(Node2 v) {
		while (v.up != null) {
			Node2 u = v.up;
			Node2 t = u.up;
			if (u.up != null) {
				((t.l == u) == (u.l == v) ? u : v).rotate();
			}
			v.rotate();
		}
		v.update();
	}

	int get(int idx) {
		Node1 v = nodesLC[idx];
		splay1(v, true);

		// is it needed????
		// I think v is guaranteed to be pushed after splay(v)...
		v.push();

		Node2 u = v.big;
		splay2(u);
		root = u;

		return Node2.getSize(u.l) + Node1.getSize(v.l);
	}

	void makeRoot(Node1 v) {
		Node1 initV = v;
		Node1 rest = null;
		for (; v != null; rest = v, v = v.up) {
			splay1(v, true);
			
			v.push(); //??????

			if (v.r == null) {
				// remove v.big from another tree
				Node2 u = v.big;
				splay2(u);
				if (u.l != null) {
					u.l.up = null;
				}
				if (u.r != null) {
					u.r.up = null;
				}
				if (u.r == null) {
					root = u.l;
				} else {
					Node2 t = u.r;
					while (t.l != null) {
						t = t.l;
					}
					splay2(t);
					t.l = u.l;
					if (t.l != null) {
						t.l.up = t;
					}
					t.update();
					root = t;
				}
			} else {
				// this path is now just v.r
				// modify it in the big tree
				Node1 t = v.r;

				splay2(v.big);
				root = v.big;

				t.big = root;
				v.big = null;

				root.path = t;
				root.update();
				
			}

			v.big = null;

			v.r = rest;
			v.update();
		}

		splay1(initV, false);
		initV.rev ^= true;

		Node2 tmp = new Node2(initV);
		initV.big = tmp;

		tmp.r = root;
		if (root != null) {
			root.up = tmp;
		}
		root = tmp;
		root.update();
	}

	void submit() {
		int n = nextInt();
		int q = nextInt();
		int[] a = new int[2 * n - 2];
		for (int i = 0; i < 2 * n - 2; i++) {
			a[i] = nextInt() - 1;
		}

		g = buildUGraph(a, n, n - 1);

		int[] init = getOrder(g);

		root = null;
		for (int i : init) {
			Node2 tmp = new Node2(nodesLC[i]);
			tmp.path.big = tmp;
			tmp.l = root;
			tmp.update();
			if (root != null) {
				root.up = tmp;
			}
			root = tmp;
		}

		while (q-- > 0) {
			String type = nextToken();
			int v = nextInt() - 1;
			if (type.equals("up")) {
				Node1 next = nodesLC[v];
				makeRoot(next);
			} else if (type.equals("when")) {
				out.println(n - get(v));
			} else if (type.equals("compare")) {
				int u = nextInt() - 1;
				if (get(v) > get(u)) {
					out.println(v + 1);
				} else {
					out.println(u + 1);
				}
			}
		}
	}

	// we also build initial link/cut tree here since we have parents
	int[] getOrder(int[][] g) {
		int n = g.length;
		if (n == 1) {
			int[] ret = {0};
			nodesLC = new Node1[n];
			for (int i = 0; i < n; i++) {
				nodesLC[i] = new Node1();
				nodesLC[i].id = i;
			}
			return ret;
		}
		int[] deg = IntStream.range(0, n).map(i -> g[i].length).toArray();

		int[] q = new int[n];
		int[] par = new int[n];
		par[n - 1] = n - 1;
		int qh = 0, qt = 0;
		q[qt++] = n - 1;

		while (qh < qt) {
			int v = q[qh++];
			for (int u : g[v]) {
				if (u != par[v]) {
					par[u] = v;
					q[qt++] = u;
				}
			}
		}

		int[] ret = new int[n];
		int ptr = n;

		PriorityQueue<Integer> pq = new PriorityQueue<>();

		for (int i = 0; i < n; i++) {
			if (deg[i] == 1) {
				pq.add(i);
			}
		}

		while (ptr > 0) {
			int v = pq.poll();
			ret[--ptr] = v;
			deg[par[v]]--;
			if (deg[par[v]] == 1) {
				pq.add(par[v]);
			}
		}

		nodesLC = new Node1[n];
		for (int i = 0; i < n; i++) {
			nodesLC[i] = new Node1();
			nodesLC[i].id = i;
		}

		for (int i = 0; i < n - 1; i++) {
			nodesLC[i].up = nodesLC[par[i]];
		}

		return ret;
	}

	int[][] buildUGraph(int[] a, int n, int m) {
		if (m == 0) {
			if (a.length == 0) {
				return new int[n][0];
			} else {
				throw new AssertionError();
			}
		}
		if (a.length % m != 0 || a.length < 2 * m) {
			throw new AssertionError("Bad array length");
		}

		int[] deg = new int[n];
		int s = a.length / m;
		for (int i = 0; i < a.length; i += s) {
			deg[a[i]]++;
			deg[a[i + 1]]++;
		}

		int[][] g = new int[n][];
		for (int i = 0; i < n; i++) {
			g[i] = new int[deg[i] * (s - 1)];
		}

		for (int i = s * (m - 1); i >= 0; i -= s) {
			int v = a[i];
			int u = a[i + 1];
			int pv = (--deg[v]) * (s - 1);
			g[v][pv] = u;
			System.arraycopy(a, i + 2, g[v], pv + 1, s - 2);

			int pu = (--deg[u]) * (s - 1);
			g[u][pu] = v;
			System.arraycopy(a, i + 2, g[u], pu + 1, s - 2);
		}

		return g;
	}

	static class Node2 {

		Node1 path;

		Node2 l, r, up;

		int size;

		void update() {
			size = Node1.getSize(path) + getSize(l) + getSize(r);
		}

		static int getSize(Node2 v) {
			return v == null ? 0 : v.size;
		}

		public Node2(Node1 path) {
			this.path = path;
			update();
		}

		static private void relink(Node2 v, Node2 u) {
			Node2 t = u.up;
			if (v != null) {
				v.up = t;
			}
			if (t != null) {
				if (t.l == u) {
					t.l = v;
				} else if (t.r == u) {
					t.r = v;
				}
			}
		}

		private void rotate() {
			Node2 u = up;

			if (u.l == this) {
				relink(r, this);
				r = u;
			} else {
				relink(l, this);
				l = u;
			}

			relink(this, u);
			u.up = this;
			u.update();
		}

		@Override
		public String toString() {
			return "path " + path.id;
		}
	}

	static class Node1 {
		
		int id;
		
		Node1 l, r, up;

		Node2 big;

		int size;
		boolean rev;

		void update() {
			size = 1 + getSize(l) + getSize(r);
		}

		void push() {
			if (rev) {
				rev = false;
				Node1 tmp = l;
				l = r;
				r = tmp;
				if (l != null) {
					l.rev ^= true;
				}
				if (r != null) {
					r.rev ^= true;
				}
			}
		}

		boolean isRoot() {
			return up == null || (up.l != this && up.r != this);
		}

		static int getSize(Node1 v) {
			return v == null ? 0 : v.size;
		}

		public Node1() {
			update();
		}

		static private void relink(Node1 v, Node1 u) {
			Node1 t = u.up;
			if (v != null) {
				v.up = t;
			}
			if (t != null) {
				if (t.l == u) {
					t.l = v;
				} else if (t.r == u) {
					t.r = v;
				}
			}
		}

		private void rotate() {
			Node1 u = up;

			if (u.l == this) {
				relink(r, this);
				r = u;
			} else {
				relink(l, this);
				l = u;
			}

			relink(this, u);
			u.up = this;
			u.update();
		}

		@Override
		public String toString() {
			return "(" + id + ")";
		}

	}

	/*
	 * static class LinkCut {
	 * 
	 * public static void expose(Node1 v) { for (Node1 rest = null; v != null;
	 * rest = v, v = v.up) { splay(v); v.r = rest; v.update(); } }
	 * 
	 * }
	 */

	void test() {

	}

	void stress() {
		for (int tst = 0;; tst++) {
			if (false) {
				throw new AssertionError();
			}
			System.err.println(tst);
		}
	}

	F() throws IOException {
		if (System.getProperty("ONLINE_JUDGE") != null) {
			is = System.in;
		} else {
			is = new FileInputStream("in.txt");
		}
		out = new PrintWriter(System.out);
		submit();
		// stress();
		// test();
		out.close();
	}

	static final Random rng = new Random();
	static final int C = 5;

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new F();
	}

	private InputStream is;
	PrintWriter out;

	private byte[] buf = new byte[1 << 14];
	private int bufSz = 0, bufPtr = 0;

	private int readByte() {
		if (bufSz == -1)
			throw new RuntimeException("Reading past EOF");
		if (bufPtr >= bufSz) {
			bufPtr = 0;
			try {
				bufSz = is.read(buf);
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
			if (bufSz <= 0)
				return -1;
		}
		return buf[bufPtr++];
	}

	private boolean isTrash(int c) {
		return c < 33 || c > 126;
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isTrash(b))
			;
		return b;
	}

	String nextToken() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!isTrash(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	String nextString() {
		int b = readByte();
		StringBuilder sb = new StringBuilder();
		while (!isTrash(b) || b == ' ') {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}

	char nextChar() {
		return (char) skip();
	}

	int nextInt() {
		int ret = 0;
		int b = skip();
		if (b != '-' && (b < '0' || b > '9')) {
			throw new InputMismatchException();
		}
		boolean neg = false;
		if (b == '-') {
			neg = true;
			b = readByte();
		}
		while (true) {
			if (b >= '0' && b <= '9') {
				ret = ret * 10 + (b - '0');
			} else {
				if (b != -1 && !isTrash(b)) {
					throw new InputMismatchException();
				}
				return neg ? -ret : ret;
			}
			b = readByte();
		}
	}

	long nextLong() {
		long ret = 0;
		int b = skip();
		if (b != '-' && (b < '0' || b > '9')) {
			throw new InputMismatchException();
		}
		boolean neg = false;
		if (b == '-') {
			neg = true;
			b = readByte();
		}
		while (true) {
			if (b >= '0' && b <= '9') {
				ret = ret * 10 + (b - '0');
			} else {
				if (b != -1 && !isTrash(b)) {
					throw new InputMismatchException();
				}
				return neg ? -ret : ret;
			}
			b = readByte();
		}
	}
}