#include <bits/stdc++.h>
using namespace std;
bool good(pair<int, int> a, pair<pair<int, int>, int> b) {
  if (a.second <= b.first.first) return true;
  return false;
}
long long f(pair<int, int> a, pair<pair<int, int>, int> b) {
  long long len = (b.first.first / a.second);
  long long pol = a.first / b.first.second + (a.first % b.first.second != 0);
  long long rul = (pol / len + (pol % len != 0));
  return rul * b.second;
}
int main() {
  int n, a, b, c;
  vector<pair<pair<int, int>, int> > oboina;
  vector<pair<int, int> > rooms;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &a, &b, &c);
    rooms.push_back(make_pair(2 * a + 2 * b, c));
  }
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &a, &b, &c);
    oboina.push_back(make_pair(make_pair(a, b), c));
  }
  long long ans = 0;
  for (int i = 0; i < rooms.size(); i++) {
    long long price = (1ll << 31);
    for (int j = 0; j < oboina.size(); j++) {
      if (good(rooms[i], oboina[j])) {
        price = min(price, f(rooms[i], oboina[j]));
      }
    }
    ans += price;
  }
  cout << ans << endl;
  return 0;
}
