Problem Code : ISHVALA

I was trying to solve question and was able to solve for sample test cases but still getting wrong ans and unable to figure out what i did wrong. Kindly help. Here’s my code:

#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
int ans[t],p=0;
while(t–){
int n,m,count=0,w=0;
cin>>n>>m;
int x,y,s,a[n][m]={},z;
cin>>x>>y>>s;
for(int i=0;i<x;i++){
cin>>z;
for(int j=0;j<m;j++){
a[z-1][j]=1;
}
}
for(int i=0;i<y;i++){
cin>>z;
for(int j=0;j<n;j++){
a[j][z-1]=1;
}
}

	for(int i=0;i<n;i++){
		w=0;
		z=0;
		for(int j=0;j<m;j++){
			if(a[i][j]==0){
				z++;
			}
			else{
				z=0;
			}
			if(z==s){
				z=0;
				for(int k=i;k<=i+s;k++){
					if(k==i+s){
						if(z==s){
						z=0;
						count++;
						w=1;
					}
					}
					else if(a[k][j]==0){
						z++;
					}
					else{
						z=0;
						break;
					}
				}
			}
		}
		if(w==1){
			i+=s-1;
		}
	}
	ans[p]=count;
	p++;
}
for(int i=0;i<p;i++){
	cout<<ans[i]<<endl;
}

}