#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
bool can(int ra, int rb, int rc, int oa, int ob, int &t) {
  int perim = (ra + rb) * 2;
  int polosok = perim / ob;
  if (perim % ob) polosok++;
  int zrulona = oa / rc;
  int ost = oa % rc;
  if (!zrulona) return 0;
  int treba = polosok / (zrulona);
  if (treba * zrulona < polosok) treba++;
  t = treba;
  return 1;
}
int main() {
  int n;
  int r[505][3];
  cin >> n;
  for (int x = 0; x < n; x++) {
    cin >> r[x][0] >> r[x][1] >> r[x][2];
  }
  int m;
  int o[505][3];
  cin >> m;
  for (int x = 0; x < m; x++) {
    cin >> o[x][0] >> o[x][1] >> o[x][2];
  }
  int rez = 0;
  for (int x = 0; x < n; x++) {
    int mi = -1;
    for (int y = 0; y < m; y++) {
      int tr;
      if (can(r[x][0], r[x][1], r[x][2], o[y][0], o[y][1], tr)) {
        if (mi == -1 || mi > tr * o[y][2]) mi = tr * o[y][2];
      }
    }
    rez += mi;
  }
  cout << rez;
  return 0;
}
