#include <bits/stdc++.h>
using namespace std;
int n, m;
int day[8];
int l[512], h[512], w[512];
int x[512], y[512], p[512];
int sum = 0;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d%d", l + i, w + i, h + i);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) scanf("%d%d%d", x + i, y + i, p + i);
  for (int i = 1; i <= n; i++) {
    int minn = 0x7fffffff;
    int len = (w[i] + l[i]) * 2;
    for (int j = 1; j <= m; j++)
      if (x[j] >= h[i]) {
        int tmp = (x[j] / h[i]);
        int tiao = len / y[j];
        if (len % y[j] != 0) tiao++;
        int num = tiao / tmp;
        if (tiao % tmp != 0) num++;
        if (num * p[j] < minn) minn = num * p[j];
      }
    sum += minn;
  }
  printf("%d\n", sum);
  return 0;
}
