def main(): import sys input = sys.stdin.read().split() idx = 0 N = int(input[idx]); idx +=1 M = int(input[idx]); idx +=1 T = int(input[idx]); idx +=1 edges = [[] for _ in range(N)] for _ in range(M): a = int(input[idx]); idx +=1 b = int(input[idx]); idx +=1 edges[a].append(b) # Build transition matrix transition = [0] * N for u in range(N): if len(edges[u]) > 0: mask = 0 for v in edges[u]: mask |= 1 << v transition[u] = mask else: transition[u] = 0 # No outgoing edges def multiply(a, b): n = len(a) result = [0] * n for i in range(n): ai = a[i] j = 0 while ai > 0 and j < n: if ai & 1: result[i] |= b[j] ai >>= 1 j += 1 return result def matrix_power(mat, power): n = len(mat) result = [0] * n # Initialize as identity matrix for i in range(n): result[i] = 1 << i while power > 0: if power % 2 == 1: result = multiply(result, mat) mat = multiply(mat, mat) power //= 2 return result powered = matrix_power(transition, T) ans = bin(powered[0]).count('1') print(ans) if __name__ == '__main__': main()