#include <bits/stdc++.h>
using namespace std;
struct oboi {
  int len;
  int width;
  int price;
};
struct comn {
  int len;
  int width;
  int height;
};
int main() {
  int n;
  cin >> n;
  vector<comn> vComn(n);
  for (int i = 0; i < n; ++i) {
    comn tmp = comn();
    cin >> tmp.len >> tmp.width >> tmp.height;
    vComn[i] = tmp;
  }
  int m;
  cin >> m;
  vector<oboi> vOboi(m);
  for (int i = 0; i < m; ++i) {
    oboi t = oboi();
    cin >> t.len >> t.width >> t.price;
    vOboi[i] = t;
  }
  int res = 0;
  for (int i = 0; i < n; ++i) {
    int per = 2 * (vComn[i].len + vComn[i].width);
    int min = 1000 * 1000 * 1000;
    for (int j = 0; j < m; ++j) {
      int pol = ceil(double(per) / vOboi[j].width);
      int tres = 0;
      if (vOboi[j].len >= vComn[i].height) {
        tres = ceil(double(pol) / ((vOboi[j].len) / vComn[i].height));
        if (tres * vOboi[j].price < min) min = tres * vOboi[j].price;
      }
    }
    res += min;
  }
  cout << res;
  return 0;
}
