#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 1<<30

typedef pair<int,int> pii;

int dp[1000][1000];         // dp[i][j] : ³ i, ¼a j ÜÅÌÍÍÉ¨³Üé
int m,n;
int h1[100];
int r1[100];
int h2[100];
int r2[100];

int solve(int h, int r, int x, int y) { // x : êYÌðã©çÇ±ÜÅgÁ½©@y : ñY
  // printf("%d,%d  %d,%d ",h,r,x,y);
  if (dp[h][r]>=0) {
//    cout << dp[h][r] << endl;
    return dp[h][r];
  }
  //cout << endl;
  int res = 0;
  for (int i=x-1; i>=0; --i) {
    if (h>h1[i] && r>r1[i])
      res = max(res, solve(h1[i],r1[i],i,y));
  }
  for (int i=y-1; i>=0; --i) {
    if (h>h2[i] && r>r2[i])
      res = max(res, solve(h2[i],r2[i],x,i));
  }
  return dp[h][r] = res + 1;
}

int main() {
  while(cin >> n, n) {
    REP(i,n) 
      cin >> h1[i] >> r1[i];
    cin >> m;
    REP(i,m)
      cin >> h2[i] >> r2[i];
    memset(dp,-1,sizeof(dp));
    cout << max(solve(h1[n-1],r1[n-1], n-1, m), solve(h2[m-1],r2[m-1], n, m-1)) << endl;
  }
}