#include <bits/stdc++.h>
using namespace std;
struct room {
  int width = 0;
  int height = 0;
  int length = 0;
  int sum = 0;
};
struct wallpaper {
  int width = 0;
  int length = 0;
  int price = 0;
  int sum = 0;
};
int main() {
  int n, m;
  long long price_sum = 0;
  room rooms[500];
  wallpaper wallpapers[500];
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> rooms[i].length >> rooms[i].width >> rooms[i].height;
    rooms[i].sum = rooms[i].length * 2 + rooms[i].width * 2;
  }
  cin >> m;
  for (int i = 0; i < m; ++i) {
    cin >> wallpapers[i].length >> wallpapers[i].width >> wallpapers[i].price;
  }
  for (int i = 0; i < n; ++i) {
    long long min_sum = 0;
    room r = rooms[i];
    for (int j = 0; j < m; ++j) {
      wallpaper w = wallpapers[j];
      long a = w.length / r.height * w.width;
      if (a == 0) continue;
      long b = r.sum / a;
      if (r.sum % a != 0) {
        b++;
      }
      long long sum = b * w.price;
      if (min_sum == 0 || sum < min_sum) min_sum = sum;
    }
    price_sum += min_sum;
  }
  cout << price_sum;
  return 0;
}
