#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000009;
int main() {
  int n;
  cin >> n;
  int room[n][3];
  for (int i = 0; i < n; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    room[i][0] = a;
    room[i][1] = b;
    room[i][2] = c;
  }
  int m;
  cin >> m;
  int roll[m][3];
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    roll[i][0] = a;
    roll[i][1] = b;
    roll[i][2] = c;
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int a = room[i][0];
    int b = room[i][1];
    int h = room[i][2];
    int p = 2 * (a + b);
    int mincost = INF;
    for (int j = 0; j < m; j++) {
      int hpaper = roll[j][0];
      int wpaper = roll[j][1];
      int cost = roll[j][2];
      if (hpaper >= h) {
        wpaper *= (hpaper / h);
        hpaper = h;
      } else {
        continue;
      }
      int pq = p / wpaper;
      int pm = p % wpaper;
      if (pm > 0) pq++;
      mincost = min(mincost, (pq * cost));
    }
    ans += mincost;
  }
  cout << ans << endl;
  return 0;
}
