#include <bits/stdc++.h>
const int INF = 1000000000;
const int MAXN = 500;
int l[2][MAXN], w[MAXN], h[2][MAXN], c[MAXN];
int ceil(int num, int denom) { return (num / denom) + (num % denom > 0); }
int main() {
  int n, m, i, j, cost, tmp, ans = 0;
  scanf("%d", &n);
  for (i = 0; i < n; ++i) scanf("%d%d%d", &l[0][i], w + i, &h[0][i]);
  scanf("%d", &m);
  for (i = 0; i < m; ++i) scanf("%d%d%d", &h[1][i], &l[1][i], c + i);
  for (i = 0; i < n; ++i) {
    cost = INF;
    for (j = 0; j < m; ++j)
      if (h[0][i] <= h[1][j]) {
        tmp = ceil(2 * (l[0][i] + w[i]), l[1][j] * (h[1][j] / h[0][i])) * c[j];
        if (tmp < cost) cost = tmp;
      }
    ans += cost;
  }
  printf("%d\n", ans);
  return 0;
}
