#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n;
  long long a[n], b[n], c[n];
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  cin >> m;
  long long a_[m], b_[m], c_[m];
  for (int i = 0; i < m; i++) {
    cin >> a_[i] >> b_[i] >> c_[i];
  }
  for (int i = 0; i < n; i++) {
    long long mn = 1e16;
    long long p = 2 * (a[i] + b[i]);
    for (int j = 0; j < m; j++) {
      long long k = a_[j] / c[i];
      if (k <= 0) continue;
      long long q = p / b_[j] + (p % b_[j] > 0);
      long long l = q / k + (q % k > 0);
      if (mn > l * c_[j]) {
        mn = l * c_[j];
      }
    }
    sum += mn;
  }
  cout << sum;
  return 0;
}
