#include <bits/stdc++.h>
using namespace std;
int DuzSobe[550], SirinaSobe[550], VisinaSobe[550], DuzinaTrake[550],
    SirinaTrake[550], Cena[550];
int main() {
  int n, m, Sol = 0, mini = 10000000;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &DuzSobe[i], &SirinaSobe[i], &VisinaSobe[i]);
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &DuzinaTrake[i], &SirinaTrake[i], &Cena[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int ObimSobe = 2 * (DuzSobe[i] + SirinaSobe[i]);
      int cost = 0;
      int x = 0;
      x = DuzinaTrake[j] / VisinaSobe[i];
      if (x == 0) continue;
      cost = ObimSobe / (x * SirinaTrake[j]);
      cost += ((ObimSobe % (x * SirinaTrake[j]) == 0) ? 0 : 1);
      cost *= Cena[j];
      if (cost < mini) mini = cost;
    }
    Sol += mini;
    mini = 1000000000;
  }
  printf("%d\n", Sol);
  return 0;
}
