#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[505], b[505], c[505], l[505];
int x[505], y[505], z[505];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
    l[i] = (a[i] + b[i]) * 2;
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i] >> z[i];
  }
  int cnt = 0, now = 0x7fffffff, ans = 0;
  for (int i = 0; i < n; i++) {
    now = 0x7fffffff;
    for (int j = 0; j < m; j++) {
      if (x[j] / c[i] * y[j]) {
        cnt = l[i] / (x[j] / c[i] * y[j]);
        if (l[i] % (x[j] / c[i] * y[j]) != 0) cnt++;
        now = min(now, cnt * z[j]);
      }
    }
    ans += now;
  }
  cout << ans;
  return 0;
}
