#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, len[1000], wid[1000], hei[1000], l[1000], w[1000], v[1000];
  while (cin >> n) {
    int ans = 0;
    int i, j;
    for (i = 1; i <= n; i++) cin >> len[i] >> wid[i] >> hei[i];
    int m;
    cin >> m;
    for (i = 1; i <= m; i++) cin >> l[i] >> w[i] >> v[i];
    for (i = 1; i <= n; i++) {
      int ma = 1000000;
      int peri = 2 * (len[i] + wid[i]);
      for (j = 1; j <= m; j++) {
        int div2 = l[j] / hei[i];
        if (div2 == 0) continue;
        int div = w[j] * div2;
        if (div == 0) continue;
        int ma2 = peri / div;
        if (peri % div) ma2++;
        ma = min(ma, ma2 * v[j]);
      }
      ans += ma;
    }
    cout << ans << endl;
  }
  return 0;
}
