#include <bits/stdc++.h>
using namespace std;
const bool online_judge = true;
const long long inf = 1LL << 60;
long long toInt(string s) {
  long long res;
  stringstream ss;
  ss << s;
  ss >> res;
  return res;
}
string toString(long long n) {
  stringstream ss;
  ss << n;
  return ss.str();
}
void run() {
  long long n, m;
  cin >> n;
  vector<tuple<long long, long long, long long> > rooms;
  vector<tuple<long long, long long, long long> > rolls;
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    rooms.emplace_back(a, b, c);
  }
  cin >> m;
  for (long long i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    rolls.emplace_back(a, b, c);
  }
  for (long long i = 0; i < ((long long)((rooms).size())); i++) {
    tuple<long long, long long, long long> r = rooms[i];
    long long peri = (get<0>(r) + get<1>(r)) * 2;
    long long h = get<2>(r);
    long long mincost = inf;
    for (long long j = 0; j < ((long long)((rolls).size())); j++) {
      tuple<long long, long long, long long> roll = rolls[j];
      long long rollh = get<0>(roll);
      if (rollh < h) continue;
      long long kake = rollh / h;
      long long c = ((peri) / (get<1>(roll) * kake) +
                     (0 < ((peri) % (get<1>(roll) * kake)))) *
                    get<2>(roll);
      {
        if (!online_judge)
          cerr << "c"
               << " = " << (c) << endl;
      };
      if (c < mincost) mincost = c;
    }
    {
      if (!online_judge)
        cerr << "mincost"
             << " = " << (mincost) << endl;
    };
    ans += mincost;
  }
  cout << ans << endl;
}
int main(int argc, char *argv[]) {
  run();
  return 0;
}
