#include <bits/stdc++.h>
using namespace std;
typedef struct rooms {
  int length, width, height;
};
typedef struct paper {
  int length, width, price;
};
long long int co(paper x, rooms y) {
  long long int perimeter, ef;
  perimeter = 2 * (y.length + y.width);
  int dup;
  if (x.length < y.height) return 1000008;
  dup = x.length / y.height;
  ef = perimeter / (dup * x.width);
  if (perimeter % (dup * x.width)) ef++;
  return ef * x.price;
}
int main() {
  int n, m;
  cin >> n;
  vector<paper> wall;
  vector<rooms> des;
  rooms temp;
  paper te;
  for (int i = 0; i < n; i++) {
    cin >> temp.length >> temp.width >> temp.height;
    des.push_back(temp);
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> te.length >> te.width >> te.price;
    wall.push_back(te);
  }
  long long int cs, t;
  t = 0;
  for (int i = 0; i < n; i++) {
    cs = 1000008;
    for (int j = 0; j < m; j++) {
      cs = cs > co(wall[j], des[i]) ? co(wall[j], des[i]) : cs;
    }
    t += cs;
  }
  cout << t << endl;
  return 0;
}
