#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979;
const double PI2 = 6.28318530717958;
const double PId2 = 1.570796326794895;
template <typename T>
T sqr(T x) {
  return x * x;
}
template <typename T>
T gcd(T a, T b) {
  return (b ? gcd(b, a % b) : a);
}
inline long long pw(long long n, int p) {
  long long ans = 1;
  for (int i = 0; i < p; i++) ans *= n;
  return ans;
}
inline vector<int> ReadVI(int count) {
  vector<int> arrayname(count);
  for (int i = 0; i < count; i++) cin >> arrayname[i];
  return arrayname;
}
inline vector<long long> ReadVlong(int count) {
  vector<long long> arrayname(count);
  for (int i = 0; i < count; i++) cin >> arrayname[i];
  return arrayname;
}
const int MOD = 1000000007;
const int MAXVALUE = 10000001;
int main() {
  int n, m;
  cin >> n;
  vector<int> a(n), b(n), h(n);
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> h[i];
  cin >> m;
  vector<int> lr(m), wr(m), cr(m);
  for (int i = 0; i < m; i++) cin >> lr[i] >> wr[i] >> cr[i];
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int temp = INT_MAX;
    int p = (a[i] + b[i]) * 2;
    for (int j = 0; j < m; j++) {
      if (lr[j] >= h[i]) {
        int oner = lr[j] / h[i] * wr[j];
        temp = min((p / oner + (p % oner == 0 ? 0 : 1)) * cr[j], temp);
      }
    }
    ans += temp;
  }
  cout << ans;
  return 0;
}
