import java.io.*;
import java.util.*;

/**
 * Correct solution. Works in O(E * dsu) time.
 * 
 * Solution is to build a graph for every edge color. And count number of
 * connected components, excluding 1-vertex components. DSU helps us to do that.
 * 
 * @author niyaz.nigmatullin
 * 
 */
public class metro_nn {

	static final int MOD = 1000000007;
	static final String PROBLEM_ID;
	static {
		String s = new Throwable().getStackTrace()[0].getClassName();
		PROBLEM_ID = s.substring(0, s.indexOf('_'));
	}

	static int nextInt(BufferedReader br) throws IOException {
		int c = br.read();
		while (c <= 32) {
			c = br.read();
		}
		int ret = 0;
		while (c >= '0' && c <= '9') {
			ret = ret * 10 + c - '0';
			c = br.read();
		}
		return ret;
	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new FileReader(new File(
				PROBLEM_ID + ".in")));
		PrintWriter out = new PrintWriter(PROBLEM_ID + ".out");
		int n = nextInt(br);
		int m = nextInt(br);
		int k = nextInt(br);
		List<Edge>[] edges = new List[k];
		for (int i = 0; i < m; i++) {
			Edge e = new Edge(nextInt(br) - 1, nextInt(br) - 1, nextInt(br) - 1);
			if (edges[e.color] == null) {
				edges[e.color] = new ArrayList<Edge>(2);
			}
			edges[e.color].add(e);
		}
		int[] answer = solve(n, k, edges);
		for (int i : answer) {
			out.println(i);
		}
		out.close();
	}

	static class DSU {
		int[] p;
		int[] v;
		int version;
		int[] r;
		int components;

		public DSU(int n) {
			p = new int[n];
			r = new int[n];
			v = new int[n];
			clear();
		}

		int get(int x) {
			if (v[x] != version) {
				v[x] = version;
				return p[x] = x;
			}
			return x == p[x] ? x : (p[x] = get(p[x]));
		}

		void union(int x, int y) {
			if (v[x] != version && v[y] != version) {
				components++;
			}
			if (v[x] == version && v[y] == version) {
				components--;
			}
			x = get(x);
			y = get(y);
			if (x == y) {
				components++;
				return;
			}
			if (r[x] >= r[y]) {
				p[y] = x;
				if (r[x] == r[y]) {
					++r[x];
				}
			} else {
				p[x] = y;
			}
		}

		void clear() {
			++version;
			components = 0;
		}
	}

	static int[] solve(int n, int k, List<Edge>[] edges) {
		int[] answer = new int[k];
		DSU dsu = new DSU(n);
		for (int i = 0; i < k; i++) {
			dsu.clear();
			if (edges[i] != null) {
				for (Edge e : edges[i]) {
					dsu.union(e.from, e.to);
				}
			}
			answer[i] = dsu.components;
		}
		return answer;
	}

	static class Edge {
		int from;
		int to;
		int color;

		public Edge(int from, int to, int color) {
			this.from = from;
			this.to = to;
			this.color = color;
		}

	}
}
