#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10, INFTY = 1e10;
int N, M;
int roomX[505], roomY[505], roomZ[505];
int X[505], Y[505], price[505];
int ceil(int x, int y) {
  if (x % y == 0)
    return x / y;
  else
    return x / y + 1;
}
int floor(int x, int y) { return x / y; }
int cost(int room, int paper) {
  int p = (roomX[room] + roomY[room]) * 2;
  if (Y[paper] >= roomZ[room])
    return price[paper] * ceil(p, (X[paper] * floor(Y[paper], roomZ[room])));
  else
    return INT_MAX;
}
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    scanf("%d %d %d", &roomX[i], &roomY[i], &roomZ[i]);
  }
  cin >> M;
  for (int i = 0; i < M; i++) {
    scanf("%d %d %d", &Y[i], &X[i], &price[i]);
  }
  int lcost;
  long long tcost = 0;
  for (int room = 0; room < N; room++) {
    lcost = INT_MAX;
    for (int paper = 0; paper < M; paper++) {
      lcost = min(lcost, cost(room, paper));
    }
    tcost += lcost;
  }
  cout << tcost << "\n";
  return 0;
}
