#include <bits/stdc++.h>
using namespace std;
int wX[500];
int wY[500];
int oX[500];
int oY[500];
int oC[500];
int main(int argc, char* argv[]) {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    wX[i] = a + a + b + b;
    wY[i] = c;
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    oX[i] = b;
    oY[i] = a;
    oC[i] = c;
  }
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int minCost = INT_MAX;
    for (int j = 0; j < m; j++) {
      int nX = oY[j] / wY[i];
      if (nX == 0) continue;
      int n = (wX[i] + nX * oX[j] - 1) / (nX * oX[j]);
      int c = n * oC[j];
      minCost = min(minCost, c);
    }
    sum += minCost;
  }
  cout << sum;
  return 0;
}
