#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int i = 0;
  int j = 0;
  int rooms[1000][4];
  for (i = 0; i < n; i++) cin >> rooms[i][0] >> rooms[i][1] >> rooms[i][2];
  int posters[1000][4];
  int pos_count;
  cin >> pos_count;
  int check[pos_count + 1];
  for (i = 0; i < pos_count; i++)
    cin >> posters[i][0] >> posters[i][1] >> posters[i][2];
  int total = 0;
  for (i = 0; i < n; i++) {
    int len = rooms[i][0];
    int wid = rooms[i][1];
    int hig = rooms[i][2];
    int min = 1000000;
    int min_index = 0;
    for (j = 0; j < pos_count; j++) {
      int l = posters[j][0];
      int w = posters[j][1];
      int price = posters[j][2];
      if (l < hig) continue;
      int per = l / hig;
      int peri = 2 * (len + wid);
      int req;
      if (peri / (w * per) == peri / float(w * per))
        req = peri / (w * per);
      else
        req = peri / (w * per) + 1;
      if (req * price < min) {
        min = req * price;
        min_index = j;
      }
    }
    total += min;
  }
  cout << total << "\n";
  return 0;
}
