#include <bits/stdc++.h>
using namespace std;
struct room {
  int length;
  int width;
  int height;
};
struct paper {
  int length;
  int width;
  int price;
};
int N, M;
room R[1000];
paper P[1000];
int calc(room a) {
  int rl, rw, rh;
  rl = a.length;
  rw = a.width;
  rh = a.height;
  int tl = 2 * rl + 2 * rw;
  int mn = pow(2, 31) - 1;
  int pl, pw;
  int can_use;
  int len_of_one;
  int lagbe;
  int cost;
  for (int i = 0; i < M; i++) {
    pl = P[i].length;
    pw = P[i].width;
    if (pl < rh) {
      continue;
    } else if (pl >= rh) {
      can_use = pl / rh;
      len_of_one = pw * can_use;
      lagbe = ceil((double)tl / (double)len_of_one);
      cost = lagbe * P[i].price;
    }
    if (cost < mn) {
      mn = cost;
    }
  }
  return mn;
}
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> R[i].length >> R[i].width >> R[i].height;
  cin >> M;
  for (int i = 0; i < M; i++) cin >> P[i].length >> P[i].width >> P[i].price;
  int result = 0;
  for (int i = 0; i < N; i++) {
    result += calc(R[i]);
  }
  cout << result << endl;
  return 0;
}
