There is a city consisting of many small islands, and the citizens live in these islands. Citizens feel inconvenience in requiring ferry rides between these islands. The city mayor decided to build bridges connecting all the islands.

The city has two construction companies, A and B.
The mayor requested these companies for proposals, and obtained proposals in the form:
"Company A (or B) can build a bridge between islands *u* and *v* in *w* hundred million yen."

The mayor wants to accept some of these proposals to make a plan with the lowest budget.
However, if the mayor accepts too many proposals of one company,
the other may go bankrupt, which is not desirable for the city with only two construction companies.
However, on the other hand, to avoid criticism on wasteful construction,
the mayor can only accept the minimum number (i.e., *n* − 1) of bridges for connecting all the islands.
Thus, the mayor made a decision that exactly *k* proposals by the company A
and exactly *n* − 1 − *k* proposals by the company B should be accepted.

Your task is to write a program that computes the cost of the plan with the lowest budget that satisfies the constraints. Here, the cost of a plan means the sum of all the costs mentioned in the accepted proposals.

The input consists of multiple datasets. The number of datasets is at most 30. Each dataset is in the following format.

nmk

u_{1}v_{1}w_{1}l_{1}

...

u_{m}v_{m}w_{m}l_{m}

The first line contains three integers *n*, *m*, and *k*, where
*n* is the number of islands, *m* is the total number of proposals,
and *k* is the number of proposals that are to be ordered to company A
(2 ≤ *n* ≤ 200, 1 ≤ *m* ≤ 600, and 0 ≤ *k* ≤ *n*−1).
Islands are identified by integers, 1 through *n*.
The following *m* lines denote the proposals each of which is described with three integers
*u _{i}*,

The end of the input is indicated by a line with three zeros separated by single spaces.

For each dataset, output a single line containing a single integer that denotes the cost (in hundred million yen) of the plan with the lowest budget. If there are no plans that satisfy the constraints, output −1.

4 5 2 1 2 2 A 1 3 2 A 1 4 2 A 2 3 1 B 3 4 1 B 5 8 2 1 2 1 A 2 3 1 A 3 4 3 A 4 5 3 A 1 2 5 B 2 3 5 B 3 4 8 B 4 5 8 B 5 5 1 1 2 1 A 2 3 1 A 3 4 1 A 4 5 1 B 3 5 1 B 4 5 3 1 2 2 A 2 4 3 B 3 4 4 B 2 3 5 A 3 1 6 A 0 0 0

5 16 -1 -1

Source: ACM International Collegiate Programming Contest
, Japan Domestic Contest, Tsukuba, Japan, 2015-06-26

http://icpc.iisf.or.jp/2015-tsukuba/

http://icpc.iisf.or.jp/2015-tsukuba/