#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n;
  int h[500], a, b, C[500];
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    C[i] = 2 * (a + b);
    cin >> h[i];
  }
  cin >> m;
  int l[500], g[500], price[500];
  int ans = 0;
  for (int i = 0; i < m; i++) cin >> l[i] >> g[i] >> price[i];
  for (int i = 0; i < n; i++) {
    int tmp = 0xFFFFFFF;
    for (int j = 0; j < m; j++) {
      int L = (l[j] / h[i]) * g[j];
      if (L == 0) continue;
      int P = (C[i] + L - 1) / L * price[j];
      if (P < tmp) tmp = P;
    }
    ans += tmp;
  }
  cout << ans << endl;
  return 0;
}
