#include <bits/stdc++.h>
using namespace std;
int n, m;
int room[501][3];
int wall[501][3];
int calc(int r, int w) {
  int p = 2 * (room[r][0] + room[r][1]);
  int u = wall[w][0] / room[r][2];
  if ((u * wall[w][1]) == 0) return 100000;
  int res = (p % (u * wall[w][1]) == 0) ? 0 : 1;
  return res + p / (u * wall[w][1]);
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> room[i][0] >> room[i][1] >> room[i][2];
  cin >> m;
  for (int i = 0; i < m; i++) cin >> wall[i][0] >> wall[i][1] >> wall[i][2];
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int mn = 0x7fffffff;
    int best = -1;
    for (int j = 0; j < m; j++) {
      int u = calc(i, j);
      if (wall[j][2] * u < mn) {
        mn = wall[j][2] * u;
        best = j;
      }
    }
    ans += mn;
  }
  cout << ans << endl;
  return 0;
}
