Dynamic Forest#2953

Dynamic Forest

1 second
256 megabytes
Easy

You need to process 3 types of queries:

  1. Add an edge to the graph (link).

  2. Remove an edge from the graph (cut).

  3. Given two vertices and , return the length of the path between them (or -1 if they belong to different connected components) (get).

Initially, the graph is empty and consists of vertices and no edges. It is guaranteed that the graph remains a forest at all times. When adding an edge, it is guaranteed that this edge is not already present in the graph. When removing an edge, it is guaranteed that the edge has already been added before.

Input

The first line contains two integers and (1 \leq N \leq 10^5 + 1, 1 \leq M \leq 10^5) — the number of vertices and the number of queries. Each of the following lines contains a command (link, cut, or get) and two integers from to — the numbers of the vertices involved in the query.

Output

For each get query, output a single number — the distance between the specified vertices, or -1 if they are in different connected components.

Examples

Example 1

Loading
Loading