#include <bits/stdc++.h>
struct Wall {
  long long a, b, cost;
};
struct Room {
  long long a, b, h;
};
const long long INF = 1LL << 62;
using namespace std;
long long foo(Room r, Wall w) {
  long long len = 2 * (r.a + r.b);
  long long p = w.b / r.h;
  long long k = len / (p * w.a);
  if (len % (p * w.a) != 0) k++;
  return k * w.cost;
}
vector<Room> v1;
vector<Wall> v2;
int main() {
  int n, m;
  cin >> n;
  Room r;
  Wall w;
  for (int i = 0; i < n; i++) {
    cin >> r.a >> r.b >> r.h;
    v1.push_back(r);
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> w.b >> w.a >> w.cost;
    v2.push_back(w);
  }
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    long long mins = INF;
    for (int j = 0; j < m; j++)
      if (v1[i].h <= v2[j].b) mins = min<long long>(mins, foo(v1[i], v2[j]));
    sum += mins;
  }
  cout << sum;
  return 0;
}
