from functools import reduce ##fの単位元を要考慮、matrix_powのCの初期化 def f(x,y): return x|y def g(x,y): return x&y def matrix_mul(A,B,f,g,mod = None): nA = len(A) mA = len(A[0]) mB = len(B[0]) tmp = [[0]*mB for _ in range(nA)] if mod is None: for i in range(nA): for j in range(mB): tmp[i][j] = reduce(f,(g(A[i][k],B[k][j]) for k in range(mA))) return tmp for i in range(nA): for j in range(mB): tmp[i][j] = reduce(f,(g(A[i][k],B[k][j])%mod for k in range(mA)))%mod return tmp def matrix_pow(A,n,f,g,mod = None): nbit = list(str(bin(n))[2:]) nbit = [int(i) for i in nbit] N = len(A) C = [[False]*N for _ in range(N)] B = A for i in range(N): C[i][i] = True if mod is None: if f is None: for i in range(len(nbit)): if nbit[-1-i] == 1: C = matrix_mul(C,B,f,g) B = matrix_mul(B,B,f,g) return C for i in range(len(nbit)): if nbit[-1-i] == 1: C = matrix_mul(C,B,f,g,mod=mod) B = matrix_mul(B,B,f,g,mod=mod) return C N,M,T = map(int,input().split()) A = [[False]*N for _ in range(N)] for _ in range(M): a,b = map(int,input().split()) A[a][b] = True INIT = [[False] for _ in range(N)] INIT[0] = [True] X = matrix_pow(A,T,f,g) Y = matrix_mul(X,INIT,f,g) ans = sum(int(*Y[i]) for i in range(N)) #print(*Y[0]) print(ans)