#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int l[510], w[510], h[510];
  int pl[510], pw[510], p[510];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d %d %d", &l[i], &w[i], &h[i]);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) scanf("%d %d %d", &pl[i], &pw[i], &p[i]);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int minn = -1;
    int len = 2 * (l[i] + w[i]);
    for (int j = 0; j < m; j++) {
      int ht = h[i];
      int num = 0, num2;
      int pes = len / pw[j];
      if (len % pw[j] != 0) pes++;
      if (ht > pl[j]) continue;
      if (ht != 0) {
        num2 = pl[j] / ht;
        num += (pes / num2);
        if (pes % num2 != 0) num++;
      }
      if (minn == -1)
        minn = num * p[j];
      else
        minn = (num * p[j]) <= (minn) ? (num * p[j]) : (minn);
    }
    ans += minn;
  }
  printf("%d\n", ans);
  return 0;
}
