#include <bits/stdc++.h>
using namespace std;
struct {
  long long x, y, z;
} a[500], b[500];
int main() {
  int n, m, i, j;
  scanf("%d", &n);
  for (i = 0; i < n; ++i) scanf("%I64d%I64d%I64d", &a[i].x, &a[i].y, &a[i].z);
  scanf("%d", &m);
  for (i = 0; i < m; ++i) scanf("%I64d%I64d%I64d", &b[i].x, &b[i].y, &b[i].z);
  long long d, len, k, cost, ans = 0;
  for (i = 0; i < n; ++i) {
    cost = 1LL << 60;
    for (j = 0; j < m; ++j) {
      if (b[j].x < a[i].z) continue;
      d = b[j].x / a[i].z * b[j].y;
      len = (a[i].x + a[i].y) * 2;
      k = len / d;
      if (len % d) ++k;
      cost = min(cost, k * b[j].z);
    }
    ans += cost;
  }
  printf("%I64d\n", ans);
  return 0;
}
