Under construction

Still being built. Things may change

Ald

Time limit4sMemory limit2048 MB

Summary
Given a tree, maintain a multiset of paths under insertions and deletions and answer how many vertices lie within distance d of every path.
Level

Hard9 of 10

Topics
Tree, Divide and conquer, Segment tree
Solved
No attempts yet

Problem

A tree is given. It has nn vertices, labeled from 11 to nn.

Denote the path between vertices aa and bb as (a,b)(a, b). The dd-set of a path is the set of all vertices of the tree whose distance from at least one vertex on the path is at most dd. For example, the 00-set of a path is the set of its own vertices. The distance between two vertices is the number of edges on the path connecting them.

Let SS be a multiset of tree paths. Initially, SS is empty. Process the following queries.

  • 1 uu vv: add the path (u,v)(u, v) to SS (1≤u,v≤n1 \le u, v \le n).
  • 2 uu vv: delete one copy of the path (u,v)(u, v) from SS (1≤u,v≤n1 \le u, v \le n). (u,v)(u, v) and (v,u)(v, u) denote the same path. For example, if S={(2,3),(2,3)}S=\{(2, 3), (2, 3)\}, then the query 2 3 2 leaves S={(2,3)}S=\{(2, 3)\}. Before this query, it is guaranteed that SS contains (u,v)(u, v) or (v,u)(v, u).
  • 3 dd: print the size of the intersection of the dd-sets of all paths in SS (0≤d≤n0 \le d \le n). If SS is empty, print 00.

Input

The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). Each test case starts with a line containing the number of vertices nn and the number of queries qq (1≤n,q≤1051 \le n, q \le 10^5). The next n−1n-1 lines each contain the endpoints uiu_i and viv_i of the ii-th edge. The last qq lines contain queries in the format described above. The sum of nn over all test cases does not exceed 10510^5, and the sum of qq over all test cases does not exceed 10510^5.

Output

For each query of type 3, print the answer on its own line.

Examples1

  1. Example 1

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