#include <bits/stdc++.h>
using namespace std;
long long l[1000], r[1000], h[1000], ll[1000], rr[1000], cost[1000];
long long n, m;
long long shet(long long x, long long y) {
  long long res = 0;
  long long dlina = l[x], shirina = r[x], visota = h[x];
  long long t1, t2;
  long long per = ((dlina + shirina) << 1);
  t2 = per / rr[y];
  if (per % rr[y] != 0) t2++;
  t1 = visota / ll[y];
  if (visota % ll[y] != 0) t1++;
  if (visota * 2 > ll[y])
    res = t2 * t1;
  else {
    t1 = ll[y] / visota;
    res = t2 / t1;
    if (t2 % t1 != 0) res++;
  }
  res = res * cost[y];
  return res;
}
int main() {
  cin >> n;
  long long i, j;
  for (i = 0; i < n; i++) scanf("%I64d%I64d%I64d", &l[i], &r[i], &h[i]);
  cin >> m;
  for (i = 0; i < m; i++) scanf("%I64d%I64d%I64d", &ll[i], &rr[i], &cost[i]);
  long long ans = 0;
  long long mini;
  long long count;
  for (i = 0; i < n; i++) {
    mini = 1000000000000000000;
    for (j = 0; j < m; j++) {
      if (ll[j] >= h[i]) {
        count = shet(i, j);
        if (mini > count) mini = count;
      }
    }
    ans += mini;
  }
  cout << ans << endl;
  return 0;
}
