#include <bits/stdc++.h>
using namespace std;
const int MAX_ROOM = 500;
const int MAX_TYPE = 500;
const int INF = 2000000000;
int find_price(int l_r, int w_r, int h_r, int l_w, int w_w, int price) {
  int total_r = 2 * (l_r + w_r);
  int cost_w_n = (total_r + w_w - 1) / w_w;
  int cost_l_n = l_w / h_r;
  if (cost_l_n == 0) {
    return INF;
  }
  int cost_n = (cost_w_n + cost_l_n - 1) / cost_l_n;
  return cost_n * price;
}
int main() {
  int w_room[MAX_ROOM], l_room[MAX_ROOM], h_room[MAX_ROOM];
  int n;
  int w_wall[MAX_TYPE], l_wall[MAX_TYPE], l_price[MAX_TYPE];
  int m;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d %d", &l_room[i], &w_room[i], &h_room[i]);
  }
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d %d %d", &l_wall[i], &w_wall[i], &l_price[i]);
  }
  int price_sum = 0;
  for (int i = 0; i < n; ++i) {
    int min_price = INF;
    for (int j = 0; j < m; ++j) {
      int price_n = find_price(l_room[i], w_room[i], h_room[i], l_wall[j],
                               w_wall[j], l_price[j]);
      if (price_n < min_price) {
        min_price = price_n;
      }
    }
    price_sum += min_price;
  }
  printf("%d\n", price_sum);
  return 0;
}
