#include <bits/stdc++.h>
using namespace std;
struct R {
  int x, y, z;
} r[510];
int main() {
  int n;
  scanf("%d", &n);
  int x[510], y[510], z[510];
  for (int i = 0; i < n; ++i) {
    scanf("%d%d%d", &x[i], &y[i], &z[i]);
    x[i] = x[i] * 2 + y[i] * 2;
  }
  int k;
  scanf("%d", &k);
  for (int i = 0; i < k; ++i) scanf("%d%d%d", &r[i].x, &r[i].y, &r[i].z);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int min0 = 1e9;
    for (int j = 0; j < k; ++j) {
      int tmp = (r[j].x / z[i] * r[j].y);
      if (tmp == 0) continue;
      min0 = min(min0, (x[i] / tmp + (x[i] % tmp != 0)) * r[j].z);
    }
    ans += min0;
  }
  printf("%d\n", ans);
  return 0;
}
