#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[1000], b[1000], c[1000];
int p[1000], q[1000], r[1000];
int main() {
  scanf("%i", &n);
  for (int i = 0; i < n; i++) scanf("%i%i%i", &a[i], &b[i], &c[i]);
  scanf("%i", &m);
  for (int i = 0; i < m; i++) scanf("%i%i%i", &p[i], &q[i], &r[i]);
  int solve = 0;
  for (int i = 0; i < n; i++) {
    int currSolve = 2000000000;
    int currValue = 0;
    if (c[i] == 0) currSolve = 0;
    for (int j = 0; j < m; j++)
      if ((c[i] <= p[j]) && (c[i] != 0)) {
        int wide = (p[j] / c[i]) * q[j];
        currValue = (2 * a[i] + 2 * b[i]) / wide;
        if ((2 * a[i] + 2 * b[i]) % wide != 0) currValue += 1;
        currValue *= r[j];
        if (currSolve > currValue) currSolve = currValue;
      }
    solve += currSolve;
  }
  printf("%i\n", solve);
}
