Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi.
Mr. Kitayuta wants you to process the following q queries.
In the i-th query, he gives you two integers − ui and vi.
Find the number of the colors that satisfy the following condition: the edges of that color connect vertex ui and vertex vi directly or indirectly.
Output
For each query, print the answer in a separate line.
Note
Let's consider the first sample.
The figure above shows the first sample.
-
Vertex 1 and vertex 2 are connected by color 1 and 2.
-
Vertex 3 and vertex 4 are connected by color 3.
-
Vertex 1 and vertex 4 are not connected by any single color.