시간 제한메모리 제한제출정답맞힌 사람정답 비율
1.5 초 512 MB25121157.895%

문제

V–o_o–V and LHiC are playing a game.

At first, gritukan shows them an undirected graph with n vertices where each edge has a pile of stones on it.

After that, LHiC chooses some non-empty subset of edges of this graph that forms edge-disjoint edgesimple cycles (in other words, each connected component should have an Euler circuit). If he can’t (in other words, if the graph is acyclic), he loses immediately.

Otherwise, LHiC and V–o_o–V play a game of Nim with the piles on the chosen edges. V–o_o–V moves first. In a single move, a player may remove an arbitrary positive number of stones from a single pile. The player who cannot make a move loses.

Let’s call a graph good if LHiC can’t choose a non-empty subset of edge-disjoint cycles on which he will win Nim.

Gritukan asks q queries, can you help him?

There is a set of possible edges which can be picked by gritukan to form a good graph. Initially, this set is empty. In query i, first, an edge i connecting vertices ui and vi, with a pile of ai stones on it and weight wi, is added to the set of possible edges. After that, you should find the largest sum of weights of a good graph that gritukan can form using a subset of edges 1, 2, . . . , i.

입력

The first line contains two integers n and q: the number of vertices in the graph and the number of queries (2 ≤ n ≤ 64, 1 ≤ q ≤ 200 000).

Each of the next q lines contains four integers ui, vi, ai, wi, describing the edge added during i-th query (1 ≤ ui, vi ≤ n, ui ≠ vi , 0 ≤ ai < 260 , 1 ≤ wi ≤ 109).

출력

Print q lines. For the i-th query, you should print the largest sum of weights of a good graph that you can form using a subset of edges 1, 2, . . . , i.

예제 입력 1

3 3
1 2 0 1
2 3 0 1
3 1 0 2

예제 출력 1

1
2
3

예제 입력 2

6 6
1 2 1 1
2 3 1 2
3 4 1 3
4 1 1 4
5 6 1 2
6 5 1 1

예제 출력 2

1
3
6
9
11
11

예제 입력 3

5 5
1 2 0 1
2 3 1 1
3 4 2 3
4 5 4 9
5 1 7 29

예제 출력 3

1
2
5
14
42

예제 입력 4

5 1
3 5 35 35

예제 출력 4

35