#include <bits/stdc++.h>
using namespace std;
int mw[3][3],qp[10][9];
int main(){
memset(qp,0,sizeof(qp));
int n,m,x,y,z,ans=0;
cin>>n;
for(int i=1;i<=n;i++){
cin>>mw[i][1]>>mw[i][2];
qp[mw[i][1]][mw[i][2]]=3;
}
cin>>m;
for(int i=1;i<=m;i++){
cin>>x>>y>>z;
qp[x][y]=z+1;
}
for(int i=1;i<=n;i++){
x=mw[i][1];
y=mw[i][2];
if(y+2<=8&&qp[x][y+1]==0){
if(qp[x+1][y+2]==2&&x+1<=9){
ans++;
qp[x+1][y+2]=1;
}
if(qp[x-1][y+2]==2&&x-1>=0){
ans++;
qp[x-1][y+2]=1;
}
}
if(x-2>=0&&qp[x-1][y]==0){
if(qp[x-2][y+1]==2&&y+1<=8){
ans++;
qp[x-2][y+1]=1;
}
if(qp[x-2][y-1]==2&&y-1>=0){
ans++;
qp[x-2][y-1]=1;
}
}
if(y-2>=0&&qp[x][y-1]==0){
if(qp[x+1][y-2]==2&&x+1<=9){
ans++;
qp[x+1][y-2]=1;
}
if(qp[x-1][y-2]==2&&x-1>=0){
ans++;
qp[x-1][y-2]=1;
}
}
if(x+2<=9&&qp[x+1][y]==0){
if(qp[x+2][y+1]==2&&y+1<=8){
ans++;
qp[x+2][y+1]=1;
}
if(qp[x+2][y-1]==2&&y-1>=0){
ans++;
qp[x+2][y-1]=1;
}
}
}
cout<<ans;
return 0;
}
/**************************************************************
Problem: 2003
User: admin
Language: C++
Result: Accepted
Time:108 ms
Memory:2072 kb
****************************************************************/