#include <bits/stdc++.h>
using namespace std;
struct node {
  int len, width, x;
  node() {}
  node(int len, int width, int x) : len(len), width(width), x(x) {}
};
node room[505], paper[505];
int solve(int room_per, int room_h, int paper_len, int paper_width) {
  if (paper_len < room_h) return 1 << 20;
  int one_can = (paper_len / room_h) * paper_width;
  return (room_per + (one_can - 1)) / one_can;
}
int main() {
  int n, m;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> room[i].len >> room[i].width >> room[i].x;
  cin >> m;
  for (int i = 0; i < m; i++)
    cin >> paper[i].len >> paper[i].width >> paper[i].x;
  int res = 0;
  for (int i = 0; i < n; i++) {
    int mini = 1 << 20;
    for (int j = 0; j < m; j++) {
      mini = min(mini, solve(2 * room[i].len + 2 * room[i].width, room[i].x,
                             paper[j].len, paper[j].width) *
                           paper[j].x);
    }
    res += mini;
  }
  cout << res << "\n";
}
