#include <bits/stdc++.h>
using namespace std;
int peri[505], ht[505];
int len[505], wid[505], cost[505];
int getcost(int i, int j) {
  if (len[j] < ht[i]) return -1;
  int t = len[j] / ht[i];
  return (int)ceil((double)peri[i] / (double)(t * wid[j])) * cost[j];
}
int main() {
  int N = ({
    int t;
    scanf("%d", &t);
    t;
  });
  for (int i = 0; i < N; i++) {
    int a = ({
      int t;
      scanf("%d", &t);
      t;
    }),
        b = ({
          int t;
          scanf("%d", &t);
          t;
        });
    peri[i] = 2 * (a + b);
    ht[i] = ({
      int t;
      scanf("%d", &t);
      t;
    });
  }
  int M = ({
    int t;
    scanf("%d", &t);
    t;
  });
  for (int i = 0; i < M; i++) {
    len[i] = ({
      int t;
      scanf("%d", &t);
      t;
    }),
    wid[i] = ({
      int t;
      scanf("%d", &t);
      t;
    }),
    cost[i] = ({
      int t;
      scanf("%d", &t);
      t;
    });
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int cur = -1;
    for (int j = 0; j < M; j++) {
      int cc = getcost(i, j);
      if (cc == -1) continue;
      if (cur == -1 || cur > cc) cur = cc;
    }
    ans += cur;
  }
  printf("%d\n", ans);
  return 0;
}
