#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
int L[maxn], W[maxn], H[maxn];
int L_[maxn], W_[maxn], P[maxn];
int main() {
  ios::sync_with_stdio(false);
  int ans = 0;
  int n, m;
  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", &L_[i], &W_[i], &P[i]);
  int mn, l, tmp;
  for (int i = 0; i < n; ++i) {
    l = (L[i] + W[i]) * 2;
    mn = INT_MAX;
    for (int j = 0; j < m; ++j) {
      tmp = L_[j] / H[i] * W_[j];
      if (tmp) {
        tmp = (l + tmp - 1) / tmp * P[j];
        mn = min(mn, tmp);
      }
    }
    ans += mn;
  }
  printf("%d\n", ans);
  return 0;
}
