#include <bits/stdc++.h>
using namespace std;
struct Room {
  int l;
  int h;
  int w;
};
struct Roll {
  int l;
  int w;
  int cost;
};
long long cal(Room r, Roll rr) {
  if (rr.l < r.h) return -1;
  long long tot = r.l * 2 + r.w * 2;
  long long strip = tot / rr.w;
  if (tot % rr.w != 0) strip++;
  long long strips_per_roll = rr.l / r.h;
  long long need = strip / strips_per_roll;
  if (strip % strips_per_roll != 0) need++;
  return rr.cost * need;
}
void solve() {
  long long n;
  cin >> n;
  vector<Room> rooms(n);
  for (auto& it : rooms) {
    cin >> it.l >> it.w >> it.h;
  }
  long long m;
  cin >> m;
  vector<Roll> rolls(m);
  for (auto& it : rolls) {
    cin >> it.l >> it.w >> it.cost;
  }
  long long res = 0;
  for (int i = 0; i < n; i++) {
    long long rc = -1;
    for (int j = 0; j < m; j++) {
      long long c = cal(rooms[i], rolls[j]);
      if (c == -1) continue;
      if (rc == -1) rc = c;
      rc = min(rc, c);
    }
    res += rc;
  }
  cout << res << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
