#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define ll long long #include #define mod % 998244353 #define rep(i,n) for(long long i = 0;i < n;i ++) ll MAX = 5'000'000'000'000'000'000LL; using namespace std; int main(){ ll h,w; cin >> h >> w; vector S(h); rep(i,h)cin >> S[i]; vector> a(h,vector(w,1)); rep(i,h){ rep(j,w){ if(S[0][0] == S[i][j])a[i][j] = 0; } } vector> b(h,vector(w,0)); rep(i,h){ rep(j,w){ ll s = 0; rep(k,i+1){ rep(l,j+1){ s += b[k][l]; } } if(s%2!=a[i][j])b[i][j] = 1; } } rep(i,h-1){ rep(j,w-1){ if(b[i+1][j+1]==1){ cout << "No" << endl; return 0; } } } ll m; cin >> m; map,ll> mp; rep(i,m){ ll a,b; cin >> a >> b; mp[{a,b-1}] = 1; } rep(i,h-1){ if(b[i+1][0] == 0){ if(mp[{1,i}] == 0){ cout << "No" << endl; return 0; } } } rep(i,w-1){ if(b[0][i+1] == 0 and mp[{2,i}] == 0){ cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }