#include <bits/stdc++.h>
using namespace std;
const char al[100] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
                      'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
                      'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
struct ou {
  int first;
  int second;
  int z;
  ou(int _first, int _second, int _z) {
    first = _first;
    second = _second;
    z = _z;
  };
  ou(){};
};
bool iss(char c) {
  if (c == 'a' || c == 'e' || c == 'o' || c == 'u' || c == 'i') return true;
  return false;
}
int main() {
  int n, k;
  cin >> n;
  vector<ou> rool;
  vector<ou> room;
  for (int i = 0; i < n; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    room.push_back(ou(x, y, z));
  }
  cin >> k;
  for (int i = 0; i < k; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    rool.push_back(ou(x, y, z));
  }
  int minsum = 0;
  for (int i = 0; i < n; i++) {
    int tempsum = 10000000;
    int x = room[i].first;
    int y = room[i].second;
    int h = room[i].z;
    for (int j = 0; j < k; j++) {
      int sum = 0;
      int p = rool[j].z;
      int dl = rool[j].first;
      int sh = rool[j].second;
      int delta = dl / h;
      if (delta == 0) {
        continue;
      } else {
        delta = sh * delta;
        int temp = ((x + y) * 2) / delta;
        if (((x + y) * 2) % delta > 0) temp++;
        sum += temp;
        tempsum = min(tempsum, sum * p);
      }
    }
    minsum += tempsum;
  }
  cout << minsum;
}
