#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 1e3 + 10;
int len[N];
int h[N];
int cost[N];
int main() {
  memset((cost), (0x3f), sizeof(cost));
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int a, b;
    cin >> a >> b >> h[i];
    len[i] = (a + b) * 2;
  }
  int m;
  cin >> m;
  while (m--) {
    int we, hi, p;
    cin >> hi >> we >> p;
    for (int i = 1; i <= n; i++) {
      if (hi >= h[i]) {
        int o = hi / h[i] * we;
        cost[i] = min(cost[i], (len[i] + o - 1) / o * p);
      }
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans += cost[i];
  cout << ans << endl;
  return 0;
}
