#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int, int>, int>> wallpapers;
int m;
int calc(int length, int width, int height) {
  int total_price = INT_MAX;
  int p = (length + width) * 2;
  for (int i = 0; i < m; ++i) {
    if (wallpapers[i].first.first < height) continue;
    int count_in_wallpaper = wallpapers[i].first.first / height;
    int cnt = p / wallpapers[i].first.second;
    if (p % wallpapers[i].first.second) cnt++;
    int wallpapers_count = cnt / count_in_wallpaper;
    if (cnt % count_in_wallpaper) wallpapers_count++;
    int price = wallpapers_count * wallpapers[i].second;
    total_price = min(total_price, price);
  }
  return total_price;
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pair<pair<int, int>, int>> rooms(n);
  for (int i = 0; i < n; ++i) {
    cin >> rooms[i].first.first >> rooms[i].first.second >> rooms[i].second;
  }
  cin >> m;
  wallpapers.resize(m);
  for (int i = 0; i < m; ++i) {
    cin >> wallpapers[i].first.first >> wallpapers[i].first.second >>
        wallpapers[i].second;
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += calc(rooms[i].first.first, rooms[i].first.second, rooms[i].second);
  }
  cout << ans;
  return 0;
}
