#include <bits/stdc++.h>
using namespace std;
template <typename T>
T inline SQR(const T &a) {
  return a * a;
}
long long MOD = 1000000007LL;
long long mypow(long long a, long long p) {
  if (p == 0) return 1LL;
  long long ans = mypow(a, p / 2);
  ans *= ans;
  ans %= MOD;
  if (p & 1) return (a * ans) % MOD;
  return ans;
}
struct room {
  int l, w, h;
};
struct wallp {
  int l, w, p;
};
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n;
  vector<room> rooms(n);
  for (int i = 0; i < n; ++i) {
    cin >> rooms[i].l >> rooms[i].w >> rooms[i].h;
  }
  cin >> m;
  vector<wallp> wallps(m);
  for (int i = 0; i < m; ++i) {
    cin >> wallps[i].l >> wallps[i].w >> wallps[i].p;
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int area = 2 * rooms[i].h * rooms[i].w + 2 * rooms[i].h * rooms[i].l;
    int val = 0x3F3F3F3F;
    for (int j = 0; j < m; ++j) {
      int npiece = wallps[j].l / rooms[i].h;
      int pieceSz = wallps[j].w * rooms[i].h;
      if (npiece) {
        val =
            min(val, (((area + pieceSz - 1) / pieceSz + npiece - 1) / npiece) *
                         wallps[j].p);
      }
    }
    ans += val;
  }
  cout << ans << endl;
  return 0;
}
