#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7, maxN = 5e5 + 6, maxV = 6561 + 5;
map<long long, long long> mp;
int n, m, x[maxN], y[maxN];
int a[maxN], b[maxN];
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> x[i];
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> b[i] >> y[i];
  }
  for (int i = 0; i < n; i++) {
    mp[a[i]] = max(mp[a[i]], (long long)x[i]);
  }
  for (int i = 0; i < m; i++) {
    mp[b[i]] = max(mp[b[i]], (long long)y[i]);
  }
  long long res = 0;
  for (auto it = mp.begin(); it != mp.end(); it++) res += it->second;
  cout << res << '\n';
}
