#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long powerMod(long long a, long long n) {
  if (n == 0) return 1;
  long long res = powerMod((a % mod * a % mod) % mod, n / 2) % mod;
  if (n % 2) return (a % mod * res % mod) % mod;
  return res;
}
bool parallel(
    pair<pair<long long, long long>, pair<long long, long long> > first) {
  if (first.first.first == first.second.first ||
      first.first.second == first.second.second)
    return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n;
  map<long long, long long> mp;
  for (long long i = 0; i < n; i++) {
    long long first, second;
    cin >> first >> second;
    mp[first] = max(mp[first], second);
  }
  cin >> m;
  for (long long i = 0; i < m; i++) {
    long long first, second;
    cin >> first >> second;
    mp[first] = max(mp[first], second);
  }
  long long ans = 0;
  for (auto it : mp) ans += it.second;
  cout << ans;
  return 0;
}
