#include <bits/stdc++.h>
using namespace std;
int n, m, cost[1005];
vector<pair<int, int> > room, paper;
long long calculate(pair<int, int> a, pair<int, int> b) {
  int i, j;
  if (b.first < a.first) return 10000000;
  long long x = (b.first / a.first) * b.second;
  return (long long)(a.second - 1) / x + 1;
}
int main() {
  int i, j, a, b, x;
  long long res = 0;
  scanf("%d", &n);
  room.assign(n, pair<int, int>());
  for (i = 0; i < n; i++) {
    scanf("%d %d %d", &a, &b, &x);
    room[i] = pair<int, int>(x, (a + b) * 2);
  }
  scanf("%d", &m);
  paper.assign(m, pair<int, int>());
  for (i = 0; i < m; i++)
    scanf("%d %d %d", &paper[i].first, &paper[i].second, &cost[i]);
  for (i = 0; i < n; i++) {
    long long mn = 10000000;
    for (j = 0; j < m; j++)
      mn = min(mn, calculate(room[i], paper[j]) * cost[j]);
    res += mn;
  }
  cout << res;
  return 0;
}
