#include <bits/stdc++.h>
using namespace std;
const double eps = 1E-3;
const int pinf = 1E+9;
const int minf = 1E-9;
inline double sqr(double k) { return k * k; }
vector<long long> price, types;
vector<pair<int, int> > v1, v2;
void count(int i, int j);
int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  int n, m, t, t1;
  long long sum = 0;
  cin >> n;
  v1 = vector<pair<int, int> >(n);
  for (int i = 0; i < n; ++i) {
    cin >> t >> t1 >> v1[i].second;
    v1[i].first = 2 * t + 2 * t1;
  }
  cin >> m;
  v2 = vector<pair<int, int> >(m);
  types = price = vector<long long>(m);
  for (int i = 0; i < m; ++i) cin >> v2[i].first >> v2[i].second >> types[i];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) count(i, j);
    sum += *min_element(price.begin(), price.end());
  }
  cout << sum;
  return 0;
}
void count(int i, int j) {
  int ost1 = 0, w = 0, n = 0;
  price[j] = types[j] * ceil(static_cast<double>(v1[i].first) /
                             (v2[j].first / v1[i].second * v2[j].second));
  if (price[j] < 1) price[j] = pinf;
}
