#include <bits/stdc++.h>
using namespace std;
int k;
long long go(long long a, long long e, long long c, long long b[][3]) {
  long long m = 0, i, min = 1000000000000000, p;
  long long s;
  s = (a * c + e * c) * 2;
  for (i = 0; i < k; i++) {
    m = (b[i][0] / c) * c * b[i][1];
    if (m == 0) continue;
    if (s % m == 0)
      m = s / m;
    else
      m = s / m + 1;
    p = m * b[i][2];
    if (p <= min) min = p;
  }
  return min;
}
int main() {
  long long n, i, j, q, sum = 0;
  long long a[500][3], b[500][3];
  cin >> n;
  for (i = 0; i < n; i++)
    for (j = 0; j < 3; j++) cin >> a[i][j];
  cin >> k;
  for (i = 0; i < k; i++)
    for (j = 0; j < 3; j++) cin >> b[i][j];
  for (i = 0; i < n; i++) {
    q = go(a[i][0], a[i][1], a[i][2], b);
    sum = sum + q;
  }
  cout << sum;
  return 0;
}
