Killing Dragons

No attempts yetTime limit2sMemory limit256 MB

Problem

Dragon country has NN cities and MM roads. The cities are numbered 11 through NN, and each road joins two different cities. Every road can be walked in both directions.

KK dragons live in the country. Dragon ii lives in city CiC_i, starts with SiS_i heads, and grows NiN_i new heads every minute while it is alive. A dragon with at least one head is alive, and a dragon whose heads are all cut off dies. A dead dragon never grows a head again.

You hire warriors to wipe the dragons out. You pick the starting city of every warrior, and from minute 1 on, each minute runs in this order.

  1. Every warrior does one of three things. Move to a city joined to the current city by a road. Pick one living dragon in the current city and cut off one of its heads. Do nothing.
  2. Once all of that minute's actions are done, every dragon that still has at least one head grows NiN_i more heads.

Several dragons may live in one city, and several warriors may cut heads off the same dragon in the same minute. Warriors travel only along roads, so they cannot move between cities that no chain of roads connects.

You choose the starting city and every action of every warrior. Find the smallest number of warriors that kills all of the dragons within a finite number of minutes.

Input

The input holds several test cases.

The first line of each test case has three integers NN, MM, KK (1N3001 \le N \le 300, 0MN(N1)0 \le M \le N(N-1), 1K10001 \le K \le 1000). Each of the next MM lines holds one road as two integers aa, bb (1abN1 \le a \ne b \le N), a road between city aa and city bb. The same pair of cities may be given more than once. Each of the next KK lines holds one dragon, and line ii has three integers CiC_i, SiS_i, NiN_i (1CiN1 \le C_i \le N, 1Si1051 \le S_i \le 10^5, 0Ni1050 \le N_i \le 10^5).

The line after the last test case is 0 0 0, and that line is not processed.

Output

For each test case, print on one line the smallest number of warriors that kills all of the dragons.