#include <bits/stdc++.h>
using namespace std;
long long int wari(long long int a, long long int b) {
  long long int res = (long long int)a / b;
  if (a % b != 0) res++;
  return res;
}
int main() {
  long long int n, m;
  long long int nx[501], ny[501], nz[501], mx[501], my[501], mz[501];
  long long int cost = 1000000000;
  long long int t1, t2;
  long long int res = 0;
  long long int kosu;
  cin >> n;
  for (long long int i = 0; i < ((long long int)(n)); i++)
    cin >> nx[i] >> ny[i] >> nz[i];
  cin >> m;
  for (long long int i = 0; i < ((long long int)(m)); i++)
    cin >> mx[i] >> my[i] >> mz[i];
  for (long long int i = 0; i < ((long long int)(n)); i++) {
    cost = 1000000000;
    t1 = (nx[i] + ny[i]) * 2;
    for (long long int j = 0; j < ((long long int)(m)); j++) {
      t2 = mx[j] / nz[i];
      if (t2 != 0) {
        kosu = wari(t1, t2 * my[j]);
        cost = min(cost, kosu * mz[j]);
      }
    }
    res += cost;
  }
  cout << res << endl;
  return 0;
}
