mod = 10**9+7 def main(): n, m, t = map(int, input().split()) A = [[0]*n for i in range(n)] for i in range(m): a, b = map(int, input().split()) A[b][a] = 1 #print(A) # A*B def mat_mul(A, B, mod): C = [[0]*len(B[0]) for i in range(len(A))] for i in range(len(A)): for k in range(len(B)): for j in range(len(B[0])): C[i][j] = (C[i][j] + A[i][k]*B[k][j])%mod return C #A**n def mat_pow(A, n, mod): B = [[0]*len(A) for i in range(len(A))] for i in range(len(A)): B[i][i] = 1 while n > 0: if n & 1 == 1: B = mat_mul(A, B, mod) A = mat_mul(A, A, mod) n = n>>1 return B X = [0]*n X[0] = 1 A = mat_pow(A, t, mod) ans = 0 for i in range(n): s = 0 for j in range(n): s += A[i][j]*X[j] if s: ans += 1 #print(A) print(ans) if __name__ == '__main__': main()