#include <bits/stdc++.h>
using namespace std;
struct Room {
  int length, width, height, total_length;
} room[500];
struct Wallpaper {
  int length, width, price;
} wallpaper[500];
int main() {
  int n, m, i, j, ans, tmp, price, ret;
  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> room[i].length >> room[i].width >> room[i].height;
    room[i].total_length = 2 * (room[i].length + room[i].width);
  }
  cin >> m;
  for (i = 0; i < m; ++i)
    cin >> wallpaper[i].length >> wallpaper[i].width >> wallpaper[i].price;
  for (ret = i = 0; i < n; ++i) {
    for (price = 500 * 500 * 500, ans = j = 0; j < m; ++j) {
      tmp = wallpaper[j].length / room[i].height;
      tmp *= wallpaper[j].width;
      if (tmp == 0) continue;
      ans = (room[i].total_length / tmp +
             (room[i].total_length % tmp == 0 ? 0 : 1)) *
            wallpaper[j].price;
      price = min(price, ans);
    }
    ret += price;
  }
  cout << ret << endl;
}
