// Arup Guha
// 3/5/2024
// Solution to Kattis Problem: Red Blue Tree

import java.util.*;
import java.io.*;

public class redbluetree {

	public static void main(String[] args) throws Exception {
	
		FastScanner stdin = new FastScanner(System.in);
		int n = stdin.nextInt();
		int numE = stdin.nextInt();
		int k = stdin.nextInt();
		
		// g1 blue = 1
		ArrayList[] g1 = new ArrayList[n];
		for (int i=0; i<n; i++) g1[i] = new ArrayList<edge>();
		
		// g2 blue = 0
		ArrayList[] g2 = new ArrayList[n];
		for (int i=0; i<n; i++) g2[i] = new ArrayList<edge>();
		
		// Read the edges.
		for (int i=0; i<numE; i++) {
			char c = stdin.next().charAt(0);
			int u = stdin.nextInt()-1;
			int v = stdin.nextInt()-1;
			
			// Weights of edges in both graphs.
			int g1w = c == 'B' ? 1 : 0;
			int g2w = 1 - g1w;
			
			// Add each edge in both graphs from both vertices.
			g1[u].add(new edge(u, v, g1w));
			g2[u].add(new edge(u, v, g2w));
			g1[v].add(new edge(v, u, g1w));
			g2[v].add(new edge(v, u, g2w));
		}
		
		// Fewest number of blue edges.
		int low = prims.mst(g1, 0);
		
		// mst call is fewest red, so max blue is the rest of the vertices.
		int high = n - 1 - prims.mst(g2, 0);

		// Ta da!
		if (low <= k && k <= high)
			System.out.println(1);
		else
			System.out.println(0);
	}
}

class edge implements Comparable<edge> {

	public int v1;
	public int v2;
	public int w;

	public edge(int a, int b, int weight) {
		v1 = a;
		v2 = b;
		w = weight;
	}

	public int compareTo(edge other) {
		return this.w - other.w;
	}
}

class prims {

	public static int mst(ArrayList[] graph, int v) {

		// Mark vertex v as being in mst.
		int n = graph.length;
		boolean[] used = new boolean[n];
		used[v] = true;

		// Add all of v's edges into the priority queue.
		PriorityQueue<edge> pq = new PriorityQueue<edge>();
		for (int i=0; i<graph[v].size(); i++)
			pq.offer( ((ArrayList<edge>)graph[v]).get(i));

		int numEdges = 0, res = 0;

		while (pq.size() > 0) {

			// Get next edge.
			edge next = pq.poll();
			if (used[next.v1] && used[next.v2]) continue;

            // Add new items to priority queue - need to check which vertex is new.
			if (!used[next.v1]) {
                for (int i=0; i<graph[next.v1].size(); i++)
                    pq.offer( ((ArrayList<edge>)graph[next.v1]).get(i));
                used[next.v1] = true;
			}
			else {
                for (int i=0; i<graph[next.v2].size(); i++)
                    pq.offer( ((ArrayList<edge>)graph[next.v2]).get(i));
                used[next.v2] = true;
			}

			// Bookkeeping
			numEdges++;
			res += next.w;
			if (numEdges == n-1) break;
		}

		// -1 indicates no MST, so not connected.
		return numEdges == n-1 ? res : -1;
	}
}

class FastScanner {
 
	BufferedReader br;
	StringTokenizer st;
 
	public FastScanner(InputStream i) {
		br = new BufferedReader(new InputStreamReader(i));
		st = new StringTokenizer("");
	}
 
	public String next() throws IOException {
		if(st.hasMoreTokens())
			return st.nextToken();
		else
			st = new StringTokenizer(br.readLine());
		return next();
	}
 
	public int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(next());
	}
}