#include <bits/stdc++.h>
using namespace std;
struct walls {
  int peri, h;
  walls() {}
  walls(int a, int b) {
    peri = a;
    h = b;
  }
};
struct rolls {
  int l, w, c;
  rolls() {}
  rolls(int a, int b, int m) {
    l = a;
    w = b;
    c = m;
  }
};
vector<walls> wo;
vector<rolls> ro;
int t_w;
int t_r;
int main() {
  scanf("%d", &t_w);
  for (int i = 0; i < t_w; i++) {
    int a, b, c;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    a = a * 2 + b * 2;
    wo.push_back(walls(a, c));
  }
  scanf("%d", &t_r);
  for (int i = 0; i < t_r; i++) {
    int a, b, c;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    ro.push_back(rolls(a, b, c));
  }
  int final = 0;
  for (int i = 0; i < t_w; i++) {
    int p = wo[i].peri;
    int hi = wo[i].h;
    int ans = (int)13e7;
    for (int j = 0; j < t_r; j++) {
      int total_height = ro[j].l;
      int total_width = ro[j].w;
      int co = (int)13e7 - 1;
      if (total_height >= hi) {
        co = total_height / hi;
        co = co * total_width;
        int temp = co;
        co = (p / co);
        if (p % temp != 0) co++;
        co = co * ro[j].c;
      }
      ans = min(ans, co);
    }
    final += ans;
  }
  printf("%d\n", final);
  return 0;
}
