#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  int n, m;
  vector<int> room_l, room_w, room_h, wp_l, wp_w, price;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    room_l.push_back(temp);
    cin >> temp;
    room_w.push_back(temp);
    cin >> temp;
    room_h.push_back(temp);
  }
  cin >> m;
  for (int j = 0; j < m; j++) {
    int temp;
    cin >> temp;
    wp_l.push_back(temp);
    cin >> temp;
    wp_w.push_back(temp);
    cin >> temp;
    price.push_back(temp);
  }
  int total_cost = 0;
  for (int i = 0; i < n; i++) {
    int min_cost = -1;
    for (int j = 0; j < m; j++) {
      if (wp_l[j] < room_h[i]) {
        continue;
      }
      int len_total = (room_w[i] + room_l[i]) * 2;
      int strips_needed = (len_total - (len_total % wp_w[j])) / wp_w[j];
      if (len_total % wp_w[j] != 0) strips_needed += 1;
      int strips_per_roll = (wp_l[j] - (wp_l[j] % room_h[i])) / room_h[i];
      int cost =
          price[j] * ((strips_needed - (strips_needed % strips_per_roll)) /
                      strips_per_roll);
      if (strips_needed % strips_per_roll != 0) cost += price[j];
      if (min_cost < 0 || min_cost > cost) {
        min_cost = cost;
      }
    }
    total_cost += min_cost;
  }
  cout << total_cost;
  return 0;
}
