Finite Walking

아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

You are given an undirected graph GG with nn vertices and mm edges. Loops and multiple edges are allowed. Each edge has a positive integer a_ia\_i assigned to it, and a counter b_ib\_i which is initially zero.

Consider the following process on this graph: we choose the starting vertex v_1v\_1 arbitrarily, then we go along some edge e_1e\_1 starting in v_1v\_1 and ending in v_2v\_2, then we go along some edge e_2e\_2 from v_2v\_2 to v_3v\_3 and so on. In other words, we follow some path in the graph, which may contain some edges and vertices multiple times. Every time we traverse edge ii in any direction, its counter b_ib\_i changes to (b_i+1)moda_i(b\_i + 1) \bmod a\_i. We can stop the process after any number of steps (possibly, zero).

Let us call the array (b_1,b_2,,b_m)(b\_1, b\_2, \ldots, b\_m) after this process a configuration array. Consider all possible processes corresponding to all possible finite paths in GG. How many different configuration arrays can they produce? Two configuration arrays are considered different if they differ in at least one element. As the answer can be quite large, give it modulo 109+710^9 + 7.

입력

The first line of input contains two space-separated integers nn, mm (1n21051 \le n \le 2 \cdot 10^5, 0m41050 \le m \le 4 \cdot 10^5) --- number of vertices and number of edges of the graph respectively.

Next mm lines contain the description of edges, one per line: ii-th edge is described by three integers u_iu\_i, v_iv\_i, a_ia\_i (1u_i,v_in1 \le u\_i, v\_i \le n, 1a_i1091 \le a\_i \le 10^9) --- the endpoints of the edge and the number assigned to this edge. Vertices are indexed starting from 1.

Note that loops and multiple edges are allowed.

출력

In the only line print the number of different configuration arrays modulo 109+710^9 + 7.