#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i,a,n) for(ll i=a;i<n;i++)
#define w(x) ll _t;cin>>_t;f(x,1,_t+1)
#define br cout<<"\n"
#define N 10000000
ll md=1e9+7,n;
ll h,w,m;
//l,d,r,u
ll x[]={0,1,0,-1};
ll y[]={1,0,-1,0};
ll mat[1501][1501];
bool isSafe(ll i,ll j){
    return i>=0 && i<h && j>=0 && j<w;
}

map<pair<ll,ll>,vector<ll>> mp;

void dfs(ll i,ll j,ll cur_dir){
    if(!isSafe(i,j)) return ;
    if(mat[i][j]==2) return ;
    if(mat[i][j]==-1){
        if(cur_dir ==0 || cur_dir ==2) mp[{i,j}][0]=mp[{i,j}][2]=0;
        if(cur_dir ==1 || cur_dir ==3) mp[{i,j}][1]=mp[{i,j}][3]=0;
    }
    else
        mat[i][j]=1;
    dfs(i+x[cur_dir],j+y[cur_dir],cur_dir);
}

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    
    //w(_x)
    {
        ll ans=0;
        cin>>h>>w>>n>>m;
        vector<pair<ll,ll>> bulb;
        ll bi,bj;
        f(i,0,h) f(j,0,w) mat[i][j]=0;
        f(ti,0,n){
            cin>>bi>>bj;
            mat[bi-1][bj-1]=-1;
            bulb.push_back({bi-1,bj-1});
            mp[{bi-1,bj-1}].push_back(1);
            mp[{bi-1,bj-1}].push_back(1);
            mp[{bi-1,bj-1}].push_back(1);
            mp[{bi-1,bj-1}].push_back(1);
        }
        f(i,0,m){
            cin>>bi>>bj;
            mat[bi-1][bj-1]=2;
        }
        f(i,0,n){
            bi=bulb[i].first;
            bj=bulb[i].second;
            if(mp[{bi,bj}][0]) dfs(bulb[i].first+x[0],bulb[i].second+y[0],0);
            if(mp[{bi,bj}][1]) dfs(bulb[i].first+x[1],bulb[i].second+y[1],1);
            if(mp[{bi,bj}][2]) dfs(bulb[i].first+x[2],bulb[i].second+y[2],2);
            if(mp[{bi,bj}][3]) dfs(bulb[i].first+x[3],bulb[i].second+y[3],3);
        }
        f(i,0,h) f(j,0,w) if(mat[i][j]==1 || mat[i][j]==-1) ans++;
        cout<<ans;
    }
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)((n)-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int t; cin >> t;
    while(t--){
        string s; cin >> s;
        int ans = -1;
        if("atcoder" < s){
            ans = 0;
        }else{
            rep(j,s.size()){
                if('a' < s[j]){
                    if('t' < s[j]){
                        ans = j-1;
                    }else{
                        ans = j;
                    }
                    break;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}