#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j;
  int n, m;
  int hl[500], hw[500], hh[500], htl[500];
  int pl[500], pw[500], pp[500];
  cin >> n;
  for (int i = 0; i < (int)(n); i++) {
    cin >> hl[i] >> hw[i] >> hh[i];
    htl[i] = 2 * hl[i] + 2 * hw[i];
  }
  cin >> m;
  for (int i = 0; i < (int)(m); i++) cin >> pl[i] >> pw[i] >> pp[i];
  long long ans = 0;
  for (int i = 0; i < (int)(n); i++) {
    long long tmp = 1000000000LL;
    for (int j = 0; j < (int)(m); j++) {
      int num = pl[j] / hh[i];
      if (num == 0) continue;
      int len = pw[j] * num;
      int hoge = htl[i] / len;
      if (htl[i] % len) hoge++;
      tmp = min(tmp, (long long)pp[j] * hoge);
    }
    ans += tmp;
  }
  cout << ans << endl;
}
