#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<int> le(n);
  vector<int> wi(n);
  vector<int> hi(n);
  for (int i = 0; i < n; i++) cin >> le[i] >> wi[i] >> hi[i];
  int m;
  cin >> m;
  vector<int> lem(m);
  vector<int> wim(m);
  vector<int> him(m);
  for (int i = 0; i < m; i++) cin >> lem[i] >> wim[i] >> him[i];
  long long out = 0;
  for (int i = 0; i < n; i++) {
    int area = 2 * (le[i] + wi[i]) * hi[i];
    int miin = 1e9;
    for (int j = 0; j < m; j++) {
      if (lem[j] >= hi[i])
        miin =
            min(miin,
                ((int)ceil((double)area / ((lem[j] / hi[i]) * hi[i] * wim[j])) *
                 him[j]));
    }
    out += miin;
  }
  cout << out;
}
