#include <bits/stdc++.h>
using namespace std;
int calc_cost(int l, int b, int h, int lr, int wr, int cost) {
  int unit = (lr / h) * wr;
  int ans = 2 * (l + b) / unit;
  if ((2 * (l + b)) % unit) ans++;
  return ans * cost;
}
int main() {
  int i, j, n, m, dim[501][3], roll[501][3], total = 0, temp, cost;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d %d %d", &dim[i][0], &dim[i][1], &dim[i][2]);
  }
  scanf("%d", &m);
  for (i = 0; i < m; i++) {
    scanf("%d %d %d", &roll[i][0], &roll[i][1], &roll[i][2]);
  }
  for (i = 0; i < n; i++) {
    cost = 1000000000;
    temp = 1000000000;
    for (j = 0; j < m; j++) {
      if (dim[i][2] <= roll[j][0])
        temp = calc_cost(dim[i][0], dim[i][1], dim[i][2], roll[j][0],
                         roll[j][1], roll[j][2]);
      if (temp < cost) cost = temp;
    }
    total += cost;
  }
  printf("%d", total);
  return 0;
}
