import sys input = sys.stdin.buffer.readline # nxnの行列積 # n is necessary n, m, t = map(int, input().split()) graph = [[0] * (n) for _ in range(n)] for _ in range(m): a, b = map(int, input().split()) a, b = a - 1, b - 1 graph[a][b] = 1 # nxnの行列積 # n is necessary mod = 10 ** 9 + 7 def matrix_product(A, B, mod): res = [[0] * n for _ in range(n)] for i in range(n): for k in range(n): for j in range(n): res[i][j] += A[i][k] * B[k][j] res[i][j] %= mod return res def matrix_exponents(A, t, mod): res = [[0] * n for _ in range(n)] for i in range(n): res[i][i] = 1 while t > 0: if t & 1 == 1: res = matrix_product(res, A, mod) A = matrix_product(A, A, mod) t //= 2 return res res1 = matrix_exponents(graph, t, 10 ** 9 + 7) res2 = matrix_exponents(graph, t, 10 ** 9 + 9) ans = 0 for j in range(n): if res1[0][j] > 0 and res2[0][j]: ans += 1 print(ans)