Journeys

No attempts yetTime limit1sMemory limit128 MB

Problem

There are nn towns in Byteotia, numbered from 11 to nn. Highways are built rarely, but when they are, they come in large batches. In total mm batches have been built. The ii-th batch consists of every highway that connects a town numbered in [ai,bi][a_i, b_i] with a town numbered in [ci,di][c_i, d_i]. Highways meet only at towns, but they may pass one another through tunnels or overpasses. The highway network lets you travel between any pair of towns. Riding a single highway costs exactly 11 dollar.

Byteasar is returning home to settle in the capital, Bitcity, which is town pp. He wants to visit old friends scattered across the towns, so he needs the cheapest travel cost from Bitcity to every other town using only highways. Help him compute it.

Input

The first line contains three integers nn, mm, and pp (2n5000002 \le n \le 500000, 1m1000001 \le m \le 100000, 1pn1 \le p \le n): the number of towns, the number of highway batches, and the town where Byteasar lives (Bitcity).

Each of the next mm lines describes one batch with four integers aia_i, bib_i, cic_i, did_i (1aibin1 \le a_i \le b_i \le n, 1cidin1 \le c_i \le d_i \le n, [ai,bi][ci,di]=[a_i, b_i] \cap [c_i, d_i] = \varnothing). It means that every town in [ai,bi][a_i, b_i] is joined by a bidirectional highway to every town in [ci,di][c_i, d_i]. Each highway belongs to at most one batch.

Output

Print nn lines. The ii-th line must contain the minimum cost, in dollars, of travelling from Bitcity to town ii. The pp-th line is therefore 00.

Hint