#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[6000];
int b[6000];
int c[6000];
int price[6000];
int main() {
  cin >> n;
  int f = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
    if (c[i] == 0) f = 1;
    a[i] = a[i] * 2 + b[i] * 2;
    price[i] = 1e9;
  }
  cin >> m;
  while (m--) {
    int x, y, z;
    cin >> x >> y >> z;
    if (f == 1) continue;
    for (int i = 0; i < n; i++) {
      int R = x / c[i];
      R = R * y;
      int need = a[i];
      if (R == 0) continue;
      int CC = need / R;
      if (need % R != 0) {
        CC++;
      }
      price[i] = min(price[i], CC * z);
    }
  }
  int ans = 0;
  if (!f) {
    for (int i = 0; i < n; i++) {
      ans += price[i];
    }
  }
  cout << ans << endl;
}
