#include <bits/stdc++.h>
using namespace std;
template <class T>
T sq(T x) {
  return x * x;
}
const long long inf = 2147383647;
const double pi = 2 * acos(0.0);
const double eps = 1e-9;
const long long maxint = 2147483647;
const long long minint = -2147483648;
long long gcd(long long a, long long b) {
  while (b) {
    a = a % b;
    swap(a, b);
  }
  return a;
}
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
long long power(long long a, long long p) {
  long long res = 1, x = a;
  while (p) {
    if (p & 1) res = res * x;
    x = x * x;
    p >>= 1;
  }
  return res;
}
long long bigmod(long long a, long long p, long long mod) {
  long long res = 1, x = a;
  while (p) {
    if (p & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    p >>= 1;
  }
  return res;
}
struct room {
  int l, w, h;
} r[1000];
struct roll {
  int l, w, price;
} ro[1000];
int main() {
  long long res = 0;
  int n;
  scanf("%d", &n);
  int i;
  for (i = 0; i < n; i++) {
    scanf("%d %d %d", &r[i].l, &r[i].w, &r[i].h);
  }
  int m;
  scanf("%d", &m);
  for (i = 0; i < m; i++) {
    scanf("%d %d %d", &ro[i].l, &ro[i].w, &ro[i].price);
  }
  int j;
  for (i = 0; i < n; i++) {
    long long cost = inf * inf;
    long long temp;
    long long p = r[i].l + r[i].w;
    p *= 2;
    for (j = 0; j < m; j++) {
      long long cover = (ro[j].l / r[i].h) * ro[j].w;
      if (cover == 0) continue;
      long long need = (p + cover - 1) / cover;
      temp = need * ro[j].price;
      if (temp < cost) cost = temp;
    }
    res += cost;
  }
  printf("%lld\n", res);
  return 0;
}
