#include #define MOD 998244353ll using namespace std; using ll = long long; ll nPk(ll n, ll k){ ll ret = 1; for(ll i = n; i > n - k; --i){ ret *= i; ret %= MOD; } return ret; } bool can_set_left(vector >& graph, ll s, int i, ll t){ for(int j = 0; j < t; ++j){ if(i == j || ((s >> j) & 1) == 0){ continue; } if(graph[j][i] == 1){ return false; } } return true; } ll count_toposo(vector >& graph, vector& dp, ll s, ll t){ if(dp[s] == -1){ dp[s] = 0; for(int i = 0; i < t; ++i){ if(((s >> i) & 1) == 0){ continue; } if(can_set_left(graph, s, i, t)){ dp[s] += count_toposo(graph, dp, s - (1 << i), t); } } dp[s] %= MOD; } return dp[s]; } int main(){ ll N, M, K; cin >> N >> M >> K; vector > edges(K, pair({})); unordered_set toposo_st = {}; for(auto& [x, y] : edges){ cin >> x >> y; toposo_st.insert(--x); toposo_st.insert(--y); } unordered_map toposo_ids = {}; for(auto itr = toposo_st.begin(); itr != toposo_st.end(); ++itr){ toposo_ids[*itr] = toposo_ids.size(); } ll t = toposo_ids.size(); vector > graph(t, vector(t)); for(auto& [x, y] : edges){ graph[toposo_ids[x]][toposo_ids[y]] = 1; } vector dp(1 << t, -1); dp[0] = 1; ll ans = 0; ll p1 = nPk(N - 1, N - t); ll p2 = nPk(N - 1, N - t - 1); for(int i = M; i < N; ++i){ if(toposo_st.find(i) != toposo_st.end()){ int id = toposo_ids[i]; if(!can_set_left(graph, (1 << t) - 1, id, t)){ continue; } ans += p1 * count_toposo(graph, dp, (1 << t) - 1 - (1 << id), t) % MOD; } else{ ans += p2 * count_toposo(graph, dp, (1 << t) - 1, t) % MOD; } } ans %= MOD; cout << ans << endl; return 0; }