#include <bits/stdc++.h>
using namespace std;
long long n, m;
pair<long long, long long> a[100000];
pair<pair<long long, long long>, long long> b[100000];
long long del(long long x, long long y) {
  if (x % y == 0)
    return x / y;
  else
    return x / y + 1;
}
int main() {
  long long i, j, k, l, res = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> k >> l >> m;
    a[i] = make_pair(2 * (k + l), m);
  }
  cin >> m;
  for (i = 0; i < m; i++) {
    cin >> k >> l >> j;
    b[i] = make_pair(make_pair(k, l), j);
  }
  for (i = 0; i < n; i++) {
    long long cur = 100000000000;
    for (j = 0; j < m; j++) {
      long long u = b[j].first.first / a[i].second;
      if (u == 0) continue;
      long long rul = del(a[i].first, (u * b[j].first.second));
      cur = min(cur, rul * b[j].second);
    }
    res += cur;
  }
  cout << res;
  return 0;
}
