#include <bits/stdc++.h>
using namespace std;
int h[1100], c[1100];
long long ans[1100];
const long long INF = 1LL << (60);
int main() {
  int i, n, m, j, x, y, z;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x >> y >> h[i];
    c[i] = 2 * (x + y);
    ans[i] = INF;
  }
  cin >> m;
  for (j = 0; j < m; j++) {
    cin >> x >> y >> z;
    for (i = 0; i < n; i++) {
      long long tmp;
      tmp = x / h[i] * y;
      if (!tmp) continue;
      tmp = (c[i] - 1) / tmp + 1;
      ans[i] = min(ans[i], tmp * z);
    }
  }
  long long sum = 0;
  for (i = 0; i < n; i++) sum += ans[i];
  cout << sum << endl;
}
