#include <bits/stdc++.h>
using namespace std;
int n, m;
int l[1000], w[1000], h[1000];
int hh[1000], ww[1000], p[1000];
int cal(int l, int w, int ll, int ww) {
  if (ww < w) return 0;
  int num = ww / w;
  ll *= num;
  return (l + ll - 1) / ll;
}
int check(int pos) {
  int min = -1;
  for (int i = 0; i < m; ++i) {
    int num = cal((l[pos] + w[pos]) * 2, h[pos], ww[i], hh[i]);
    if (num && (min < 0 || num * p[i] < min)) min = num * p[i];
  }
  return min;
}
int main() {
  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", &hh[i], &ww[i], &p[i]);
  }
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    sum += check(i);
  }
  printf("%d\n", sum);
}
