#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<pair<pair<int, int>, int>> x(n);
  for (__typeof((n)) i = (0); i < (n); i += 1) {
    cin >> x[i].first.first >> x[i].first.second >> x[i].second;
  }
  int m;
  cin >> m;
  vector<pair<pair<int, int>, int>> y(m);
  for (__typeof((m)) i = (0); i < (m); i += 1) {
    cin >> y[i].first.first >> y[i].first.second >> y[i].second;
  }
  int ans = 0;
  for (__typeof((n)) i = (0); i < (n); i += 1) {
    int peri = (2 * (x[i].first.first + x[i].first.second));
    int cur = INT_MAX;
    for (__typeof((m)) j = (0); j < (m); j += 1) {
      if ((y[j].first.first / x[i].second) * y[j].first.second)
        cur = min(cur, ((peri - 1) / ((y[j].first.first / x[i].second) *
                                      y[j].first.second) +
                        1) *
                           y[j].second);
    }
    ans += cur;
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
