#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n;
  int s[n], l[n], c[n];
  for (int i = 0; i < n; i++) {
    int a;
    cin >> s[i] >> a;
    s[i] += a;
    s[i] *= 2;
    cin >> l[i];
    c[i] = 100000000;
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    int a, b, nc;
    cin >> a >> b >> nc;
    for (int j = 0; j < n; j++) {
      int ll = a / l[j];
      if (ll == 0) continue;
      ll *= b;
      ll = ((s[j] - 1) / (ll)) + 1;
      ll *= nc;
      c[j] = min(c[j], ll);
    }
  }
  long long newans = 0;
  for (int i = 0; i < n; i++) newans += c[i];
  cout << newans << endl;
  return 0;
}
