#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
struct ss {
  int a, b, c;
} e[505], bb[505];
int main() {
  int a, b, c;
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &a, &b, &c);
    e[i] = (ss){a, b, c};
  }
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &a, &b, &c);
    bb[i] = (ss){a, b, c};
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int mn = INF, te = 0, len = e[i].a + e[i].b;
    len *= 2;
    for (int j = 0; j < m; j++) {
      int nn = bb[j].a / e[i].c;
      nn *= bb[j].b;
      int x = 0;
      if (nn)
        x = len / nn;
      else
        continue;
      if (len % nn != 0) x++;
      te = x * bb[j].c;
      mn = min(te, mn);
    }
    ans += mn;
  }
  printf("%d\n", ans);
}
