Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Nguyen Huu Hoang Minh
- #include <bits/stdc++.h>
- #define sz(x) int(x.size())
- #define all(x) x.begin(),x.end()
- #define reset(x) memset(x, 0,sizeof(x))
- #define pb push_back
- #define mp make_pair
- #define fi first
- #define se second
- #define N 200005
- #define remain(x) if (x > MOD) x -= MOD
- #define ii pair<int, int>
- #define iiii pair< ii , ii >
- #define viiii vector< iiii >
- #define vi vector<int>
- #define vii vector< ii >
- #define bit(x, i) (((x) >> (i)) & 1)
- #define Task "test"
- using namespace std;
- typedef long double ld;
- int t, n, m, k, q;
- void readfile()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);cout.tie(0);
- if (fopen(Task".inp","r"))
- {
- freopen(Task".inp","r",stdin);
- //freopen(Task".out","w",stdout);
- }
- cin >> t;
- }
- int Pow(int a, int mu, int mod){
- if (mu==1) return a;
- int tmp = Pow(a,mu/2,mod);
- if (mu%2==0) return tmp*tmp%mod;
- return tmp*tmp%mod*a%mod;
- }
- void solve(){
- cin >> n >> m >> k >> q;
- vii color(q);
- for(int i=0; i<q; i++){
- cin >> color[i].fi >> color[i].se;
- color[i].fi--; color[i].se--;
- }
- int tplt = 0;
- int ir = 0, ic = 0;
- vector<bool> xc(n,0), yc(m,0);
- for(int i=q-1; i>0; i--){
- int cr = color[i].fi, cc = color[i].se;
- if (xc[cr] && yc[cc]) continue;
- while (ir < n && xc[ir]) ir++;
- while (ic < m && yc[ic]) ic++;
- if (ir==n || ic==m) continue;
- xc[cr]=1; yc[cc] = 1;
- tplt++;
- }
- const int mod = 998244353;
- cout << Pow(k,tplt,mod) << '\n';
- }
- void proc()
- {
- while (t--){
- solve();
- }
- }
- signed main()
- {
- readfile();
- proc();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement