You are managing a mobile phone network, and want to offer competitive prices to connect a network.

The network has n nodes.

Your competitor has already offered some connections between some nodes, with some fixed prices. These connections are bidirectional. There are initially m connections the competitor is offering. The i-th connection your competitor is offering will connect nodes fa_i and fb_i and costs fw_i. 

You have a list of k connections that you want to offer. It is guaranteed that this set of connection does not form any cycle. The j-th of these connections will connect nodes ga_j and gb_j. These connections are also bidirectional. The cost of these connections have not been decided yet.

You can set the prices of these connections to any arbitrary integer value. These prices are set independently for each connection. After setting the prices, the customer will choose such n - 1 connections that all nodes are connected in a single network and the total cost of chosen connections is minimum possible. If there are multiple ways to choose such networks, the customer will choose an arbitrary one that also maximizes the number of your connections in it.

You want to set prices in such a way such that all your k connections are chosen by the customer, and the sum of prices of your connections is maximized.

Print the maximum profit you can achieve, or -1 if it is unbounded.

Input

The first line of input will contain three integers n, k and m (1 ≤ n, k, m ≤ 5 ⋅ 10^5, k ≤ n-1), the number of nodes, the number of your connections, and the number of competitor connections, respectively.

The next k lines contain two integers ga_i and gb_i (1 ≤ ga_i, gb_i ≤ n, ga_i not= gb_i), representing one of your connections between nodes ga_i and gb_i. Your set of connections is guaranteed to be acyclic.

The next m lines contain three integers each, fa_i, fb_i and fw_i (1 ≤ fa_i, fb_i ≤ n, fa_i not= fb_i, 1 ≤ fw_i ≤ 10^9), denoting one of your competitor's connections between nodes fa_i and fb_i with cost fw_i. None of these connections connects a node to itself, and no pair of these connections connect the same pair of nodes. In addition, these connections are given by non-decreasing order of cost (that is, fw_{i-1} ≤ fw_i for all valid i).

Note that there may be some connections that appear in both your set and your competitor's set (though no connection will appear twice in one of this sets).

It is guaranteed that the union of all of your connections and your competitor's connections form a connected network.

Output

Print a single integer, the maximum possible profit you can achieve if you set the prices on your connections appropriately. If the profit is unbounded, print -1.

Examples

Input

4 3 6
1 2
3 4
1 3
2 3 3
3 1 4
1 2 4
4 2 8
4 3 8
4 1 10


Output

14


Input

3 2 1
1 2
2 3
1 2 30


Output

-1


Input

4 3 3
1 2
1 3
1 4
4 1 1000000000
4 2 1000000000
4 3 1000000000


Output

3000000000

Note

In the first sample, it's optimal to give connection 1-3 cost 3, connection 1-2 cost 3, and connection 3-4 cost 8. In this case, the cheapest connected network has cost 14, and the customer will choose one that chooses all of your connections.

In the second sample, as long as your first connection costs 30 or less, the customer chooses both your connections no matter what is the cost of the second connection, so you can get unbounded profit in this case.
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class DivCmb_504F {

	int nV;
	int nOE;
	int nUE;

	int[] dsPar;
	int[] dsRank;

	int fRoot(int cV) {
		return dsPar[cV] == cV ? cV : (dsPar[cV] = fRoot(dsPar[cV]));
	}

	public static void main(String[] args) throws IOException {
		new DivCmb_504F().execute();
	}

	void execute() throws IOException {
		// long sTime = System.currentTimeMillis();
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter printer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		StringTokenizer inputData = new StringTokenizer(reader.readLine());
		nV = Integer.parseInt(inputData.nextToken());
		nOE = Integer.parseInt(inputData.nextToken());
		nUE = Integer.parseInt(inputData.nextToken());

		dsPar = new int[nV];
		dsRank = new int[nV];
		for (int i = 0; i < nV; i++) {
			dsPar[i] = i;
		}

		lSt = new int[nV];
		Arrays.fill(lSt, -1);
		eInd = new int[2 * (nOE + nUE)];
		nxt = new int[2 * (nOE + nUE)];
		crit = new boolean[2 * (nOE + nUE)];

		for (int i = 1; i <= nOE; i++) {
			inputData = new StringTokenizer(reader.readLine());
			int a = Integer.parseInt(inputData.nextToken()) - 1;
			int b = Integer.parseInt(inputData.nextToken()) - 1;
			connect(a, b, true);

			int aR = fRoot(a);
			int bR = fRoot(b);
			if (aR != bR) {
				if (dsRank[aR] < dsRank[bR]) {
					dsPar[aR] = bR;
				} else if (dsRank[aR] == dsRank[bR]) {
					dsPar[aR] = bR;
					dsRank[bR]++;
				} else {
					dsPar[bR] = aR;
				}
			}
		}

		int[][] updates = new int[500_000][3];
		int nU = 0;

		for (int i = 1; i <= nUE; i++) {
			inputData = new StringTokenizer(reader.readLine());
			int a = Integer.parseInt(inputData.nextToken()) - 1;
			int b = Integer.parseInt(inputData.nextToken()) - 1;
			int c = Integer.parseInt(inputData.nextToken());
			int aR = fRoot(a);
			int bR = fRoot(b);
			if (aR != bR) {
				connect(a, b, false);

				if (Math.random() < 0.5) {
					dsPar[aR] = bR;
				} else {
					dsPar[bR] = aR;
				}
			} else {
				updates[nU][0] = a;
				updates[nU][1] = b;
				updates[nU][2] = c;
				nU++;
			}
		}

		init();

		for (int i = 0; i < nU; i++) {
			update(updates[i][0], updates[i][1], updates[i][2]);
		}

		output();

		printer.println(ans);

		printer.close();
	}

	int nE = 0;

	void connect(int a, int b, boolean c) {
		nxt[nE] = lSt[a];
		eInd[nE] = b;
		crit[nE] = c;
		lSt[a] = nE++;

		nxt[nE] = lSt[b];
		eInd[nE] = a;
		crit[nE] = c;
		lSt[b] = nE++;
	}

	long ans = 0;

	int[] lSt;
	int[] eInd;
	int[] nxt;
	boolean[] crit;

	int[] par;
	int[] depth;
	int[] heavyC;
	int[] chainS;

	int[] tInd;

	boolean[] critV;

	int[] tDef;

	// returns vCount
	int initDFS(int cV) {
		int cDeg = 1;
		int mADeg = 0;
		heavyC[cV] = -1;

		int aI = lSt[cV];
		while (aI != -1) {
			int aV = eInd[aI];
			boolean cCV = crit[aI];
			if (aV != par[cV]) {
				par[aV] = cV;
				depth[aV] = depth[cV] + 1;
				critV[aV] = cCV;

				int aDeg = initDFS(aV);
				if (aDeg > mADeg) {
					mADeg = aDeg;
					heavyC[cV] = aV;
				}
				cDeg += aDeg;
			}
			aI = nxt[aI];
		}
		return cDeg;
	}

	void init() {
		par = new int[nV];
		Arrays.fill(par, -1);
		depth = new int[nV];
		heavyC = new int[nV];
		chainS = new int[nV];

		tInd = new int[nV];

		critV = new boolean[nV];
		tDef = new int[nV];

		for (int i = 0; i < nV; i++) {
			if (par[i] == -1) {
				par[i] = -1;
				initDFS(i);
			}
		}

		int nTInd = 0;
		for (int cV = 0; cV < nV; cV++) {
			if (par[cV] == -1 || heavyC[par[cV]] != cV) {
				for (int cMem = cV; cMem != -1; cMem = heavyC[cMem]) {
					chainS[cMem] = cV;
					tInd[cMem] = nTInd++;
				}
			}
		}

		for (int cV = 0; cV < nV; cV++) {
			if (critV[cV]) {
				tDef[tInd[cV]] = Integer.MAX_VALUE;
			}
		}

		initTable(nV);
	}

	void update(int v1, int v2, int bound) {
		// if they're tied, v2 will still update
		while (chainS[v1] != chainS[v2]) {
			if (depth[chainS[v1]] > depth[chainS[v2]]) {
				updateTable(tInd[chainS[v1]], tInd[v1], bound);
				v1 = par[chainS[v1]];
			} else {
				updateTable(tInd[chainS[v2]], tInd[v2], bound);
				v2 = par[chainS[v2]];
			}
		}

		if (tInd[v1] < tInd[v2]) {
			updateTable(tInd[v1] + 1, tInd[v2], bound);
		} else {
			updateTable(tInd[v2] + 1, tInd[v1], bound);
		}
	}

	int[][] table = new int[19][500_000];

	void initTable(int nE) {
		for (int i = 1; i < 19; i++) {
			Arrays.fill(table[i], Integer.MAX_VALUE);
		}

		Arrays.fill(table[0], 0);

		for (int i = 1; i < tDef.length; i++) {
			table[0][i] = tDef[i];
		}
	}

	void updateTable(int l, int r, int bnd) {
		if (l <= r) {
			int len = r - l + 1;
			int size = 31 - Integer.numberOfLeadingZeros(len);
			int cover = 1 << size;
			table[size][l] = Math.min(table[size][l], bnd);
			table[size][r - cover + 1] = Math.min(table[size][r - cover + 1], bnd);
		}
	}

	void output() {
		for (int size = 18; size > 0; size--) {
			for (int i = 0; i < 500_000; i++) {
				table[size - 1][i] = Math.min(table[size - 1][i], table[size][i]);
				int subLen = 1 << (size - 1);
				if (i + subLen < 500_000) {
					table[size - 1][i + subLen] = Math.min(table[size - 1][i + subLen], table[size][i]);
				}
			}
		}

		for (int i = 0; i < 500_000; i++) {
			if (ans != -1) {
				if (table[0][i] == Integer.MAX_VALUE) {
					ans = -1;
				} else {
					ans += table[0][i];
				}
			}
		}
	}
}