#include <bits/stdc++.h>
using namespace std;
struct Room {
  int perim;
  int h;
};
struct List {
  int h;
  int w;
  int cost;
};
int main() {
  int n;
  cin >> n;
  vector<Room> rooms(n);
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b >> rooms[i].h;
    rooms[i].perim = (a + b) * 2;
  }
  int m;
  cin >> m;
  vector<List> lists(m);
  for (int i = 0; i < m; ++i) {
    cin >> lists[i].h >> lists[i].w >> lists[i].cost;
  }
  unsigned sum = 0;
  for (int i = 0; i < n; ++i) {
    unsigned min = -1;
    for (int j = 0; j < m; ++j) {
      int p = lists[j].h / rooms[i].h * lists[j].w;
      if (!p) continue;
      int cost = rooms[i].perim / p * lists[j].cost;
      if (rooms[i].perim % p) cost += lists[j].cost;
      min = cost < min ? cost : min;
    }
    sum += min;
  }
  cout << sum << endl;
  return 0;
}
