import sys input = sys.stdin.readline N,M,K=map(int,input().split()) mod=998244353 FACT=[1] for i in range(1,2*10**6): FACT.append(FACT[-1]*i%mod) E=[list(map(int,input().split())) for i in range(K)] DEG=[-1]*(N+1) EDGE=[[] for i in range(N+1)] LIST=[] for x,y in E: LIST.append(x) LIST.append(y) DEG[x]=max(0,DEG[x]) DEG[y]=max(0,DEG[y]) DEG[y]+=1 EDGE[x].append(y) LIST=sorted(set(LIST)) D={LIST[i]:i for i in range(len(LIST))} ind_main=0 ind_sub=0 other_main=N-M other_sub=M for l in LIST: if l<=M: ind_sub+=1 other_sub-=1 else: ind_main+=1 other_main-=1 Q=[] for i in range(N+1): if DEG[i]==0: Q.append(i) NEED=[0]*(len(LIST)) while Q: x=Q.pop() c=D[x] for to in EDGE[x]: DEG[to]-=1 NEED[D[to]]|=((1<0: print(0) exit() DP=[0]*(1<M: DP2[i|(1<0: DP4=[0]*(other_main+other_sub) DP4[0]=other_main for i in range(len(LIST)+1): for j in range(other_main+other_sub-1,-1,-1): for k in range(j+1,other_main+other_sub): DP4[k]+=DP4[j] DP4[k]%=mod ANS2=DP4[-1]*DP[-1]*FACT[other_main+other_sub-1]%mod print((ANS1+ANS2)%mod)