#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
struct P {
  int l, w, h;
} p[N], q[N];
int n, m;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> p[i].l >> p[i].w >> p[i].h;
  cin >> m;
  for (int i = 0; i < m; i++) cin >> q[i].l >> q[i].w >> q[i].h;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int mi = 0x7fffffff;
    int totlen = 2 * (p[i].l + p[i].w);
    for (int j = 0; j < m; j++) {
      int pr = q[j].l / p[i].h * q[j].w;
      if (pr == 0) continue;
      int cost = (totlen + pr - 1) / pr * q[j].h;
      mi = min(mi, cost);
    }
    ans += mi;
  }
  cout << ans << endl;
  return 0;
}
