#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int mas[1000][3];
  int v[1000][3];
  int i;
  cin >> n;
  for (i = 0; i < n; i++) cin >> mas[i][0] >> mas[i][1] >> mas[i][2];
  cin >> m;
  long long ans = 0;
  for (i = 0; i < m; i++) cin >> v[i][0] >> v[i][1] >> v[i][2];
  for (i = 0; i < n; i++) {
    int j, k, p = (mas[i][0] + mas[i][1]) * 2;
    long long ans1 = 0, answ = 1000000000;
    for (j = 0; j < m; j++)
      if (v[j][0] >= mas[i][2]) {
        k = v[j][0] / mas[i][2];
        k *= v[j][1];
        ans1 = (p / k + (p % k > 0)) * v[j][2];
        if (ans1 < answ) answ = ans1;
      }
    ans += answ;
  }
  cout << ans << endl;
}
