Under construction

Still being built. Things may change

Light Heavy Edges

Time limit2sMemory limit1024 MB

Summary
Each update makes the path between a and b heavy and resets every other edge touching its vertices to light. Each query counts heavy edges on a path.
Level

Medium7 of 10

Topics
Tree, Segment tree, Implementation
Solved
No attempts yet

Problem

You are given a tree with nn vertices. Each edge of the tree is either a light edge or a heavy edge. You must perform mm operations on the tree. Initially, all edges are light edges. There are two kinds of operations.

  1. You are given two vertices aa and bb. For every vertex xx on the path between aa and bb (including aa and bb themselves), turn all edges connected to xx into light edges. Also turn all edges on the path between aa and bb into heavy edges.

  2. You are given two vertices aa and bb. Compute the number of heavy edges on the path between aa and bb.

Input

The first line contains an integer TT, the number of test cases. Each test case starts with a line containing two integers nn and mm, where nn is the number of vertices and mm is the number of operations.

The next n−1n-1 lines each contain two integers uu and vv, describing an edge of the tree.

The next mm lines each contain three integers opiop_i, aia_i, bib_i, describing an operation. opi=1op_i = 1 means an operation of the first type, and opi=2op_i = 2 means an operation of the second type.

It is guaranteed that ai≠bia_i \ne b_i in every operation.

Output

For each operation of the second type, print the answer on its own line.

Constraints

For all test sets, T≤3T \le 3 and 1≤n,m≤1051 \le n,m \le 10^5.

Examples1

  1. Example 1

    Input
    1
    7 7
    1 2
    1 3
    3 4
    3 5
    3 6
    6 7
    1 1 7
    2 1 4
    2 2 7
    1 1 5
    2 2 7
    1 2 1
    2 1 7
    
    Expected output
    1
    3
    2
    1