#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m, room[505][5], paper[505][5], best[505], p[505];
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> room[i][1] >> room[i][2] >> room[i][3];
    p[i] = 2 * room[i][1] + 2 * room[i][2];
  }
  cin >> m;
  for (int i = 1; i <= m; i++) cin >> paper[i][1] >> paper[i][2] >> paper[i][3];
  int good;
  for (int i = 1; i <= n; i++) {
    good = 1000000000;
    for (int j = 1; j <= m; j++) {
      float t = float(p[i]) / (paper[j][1] / room[i][3]);
      float temp = ceil(t / paper[j][2]) * paper[j][3];
      if (temp < good) good = int(temp);
    }
    best[i] = good;
  }
  int tot = 0;
  for (int i = 1; i <= n; i++) tot += best[i];
  cout << tot << endl;
  return 0;
}
