#include <bits/stdc++.h>
using namespace std;
struct node {
  long long a, b, c;
} num[5200], pa[5200];
int main() {
  long long i, j, m, n, sum, ans, dan, l, w, nn;
  scanf("%lld", &n);
  for (i = 0; i < n; i++) {
    scanf("%lld %lld %lld", &num[i].a, &num[i].b, &num[i].c);
  }
  scanf("%lld", &m);
  ans = 0;
  for (i = 0; i < m; i++) {
    scanf("%lld %lld %lld", &pa[i].a, &pa[i].b, &pa[i].c);
  }
  for (i = 0; i < n; i++) {
    l = (num[i].a + num[i].b) * 2;
    w = num[i].c;
    sum = 0x3f3f3f3f;
    for (j = 0; j < m; j++) {
      dan = pa[j].a / w * pa[j].b;
      if (dan == 0) continue;
      if (l % dan == 0)
        nn = l / dan;
      else
        nn = l / dan + 1;
      sum = min(sum, nn * pa[j].c);
    }
    ans += sum;
  }
  printf("%lld\n", ans);
  return 0;
}
