#include <bits/stdc++.h>
using namespace std;
int pa[1000][10], room[1000][10];
long long anss, minn, n, m, k, tmp;
int work(int n) {
  minn = 1 << 30;
  for (int i = 0; i < m; i++) {
    if (pa[i][0] >= room[n][2]) {
      k = room[n][0] * 2 + room[n][1] * 2;
      tmp = pa[i][0] / room[n][2];
      tmp = tmp * pa[i][1];
      if (k <= tmp)
        k = 1;
      else if (k % tmp == 0)
        k = k / tmp;
      else
        k = k / tmp + 1;
      if (minn > k * pa[i][2]) minn = k * pa[i][2];
    }
  }
  return minn;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 3; j++) cin >> room[i][j];
  cin >> m;
  for (int i = 0; i < m; i++)
    for (int j = 0; j < 3; j++) cin >> pa[i][j];
  anss = 0;
  for (int i = 0; i < n; i++) {
    anss = anss + work(i);
  }
  cout << anss << endl;
  return 0;
}
