#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main(){
  int i,a,b,n,m,hn[100],rn[100],hm[100],rm[100],h[100],r[100],k[2];
  while(1){
    cin >> n;
    if(n == 0) break;
    for(i=0;i<n;i++) cin >> hn[i] >> rn[i];
    cin >> m;
    for(i=0;i<m;i++) cin >> hm[i] >> rm[i];

    a = 0;
    b = 0;
    for(i=0;i<m+n;i++){
      if(a < n && b < m && hn[a] < hm[b] || a < n && b >= m){
	  h[i] = hn[a];
	  r[i] = rn[a++];
	}
      else{
	h[i] = hm[b];
	r[i] = rm[b++];
      }
    }

      k[0] = 1;
      for(i=1;i<m+n;i++){
	if(h[i] > h[i-1] && r[i] > r[i-1]) k[0]++;
      }

    for(i=0;i<m+n;i++){
      if(a < n && b < m && rn[a] < rm[b] || a < n && b >= m){
	  h[i] = hn[a];
	  r[i] = rn[a++];
	}
      else{
	h[i] = hm[b];
	r[i] = rm[b++];
      }
    }

      k[1] = 1;
      for(i=1;i<m+n;i++){
	if(h[i] > h[i-1] && r[i] > r[i-1]) k[1]++;
      }

      if(k[0] > k[1]) cout << k[0] << endl;
      else cout << k[1] << endl;

  }
  return 0;
}