#include <bits/stdc++.h>
using namespace std;
int height[501], length[501];
int h[501], len[501], price[501];
int nr, np;
int main() {
  cin >> nr;
  int a, b, c;
  for (int i = 0; i < nr; i++) {
    cin >> a >> b >> c;
    length[i] = 2 * (a + b);
    height[i] = c;
  }
  cin >> np;
  for (int i = 0; i < np; i++) {
    cin >> h[i] >> len[i] >> price[i];
  }
  int ret = 0;
  for (int i = 0; i < nr; i++) {
    int MinValue = 1000000000;
    for (int j = 0; j < np; j++) {
      if (height[i] > h[j]) continue;
      int p =
          ceil((length[i] - 1e-10) / (h[j] / height[i] * len[j])) * price[j];
      MinValue = min(MinValue, p);
    }
    ret += MinValue;
  }
  cout << ret << endl;
  return 0;
}
