#include <bits/stdc++.h>
using namespace std;
int N;
int s[100005], m[100005], f[100005];
int M;
int t[100005], l[100005], r[100005];
struct interval {
  int l, r, t;
  interval() {}
  interval(int l, int r, int t) : l(l), r(r), t(t) {}
  friend bool operator<(const interval &a, const interval &b) {
    return a.r < b.r;
  }
};
set<interval> I;
struct event {
  int delta, x, y;
  int qid, type;
  event() {}
  event(int delta, int x, int y, int qid, int type)
      : delta(delta), x(x), y(y), qid(qid), type(type) {}
  friend bool operator<(const event &a, const event &b) {
    if (a.delta == b.delta) return a.type < b.type;
    return a.delta < b.delta;
  }
};
vector<event> E;
long long rate[100005];
long long top[100005];
void update(long long *f, int x, int v) {
  for (int i = x + 1; i < 100005; i += i & -i) f[i] += v;
}
long long query(long long *f, int x, int y) {
  long long ret = 0;
  for (int i = y + 1; i; i -= i & -i) ret += f[i];
  for (int i = x; i; i -= i & -i) ret -= f[i];
  return ret;
}
long long sol[100005];
void build_events() {
  for (int i = (0); i < (N); ++i) I.insert(interval(i, i, -1));
  for (int i = (0); i < (M); ++i) {
    --l[i], --r[i];
    for (auto it = I.lower_bound({l[i], l[i], 0});
         it != I.end() && it->l <= r[i]; it = I.lower_bound({l[i], l[i], 0})) {
      interval ci = *it;
      I.erase(it);
      if (ci.l < l[i]) {
        I.insert(interval(ci.l, l[i] - 1, ci.t));
        I.insert(interval(l[i], ci.r, ci.t));
      } else if (ci.r > r[i]) {
        I.insert(interval(r[i] + 1, ci.r, ci.t));
        I.insert(interval(ci.l, r[i], ci.t));
      } else if (ci.t == -1) {
        sol[i] += min((long long)m[ci.l], (long long)f[ci.l] * t[i] + s[ci.l]);
      } else {
        E.push_back(event(t[i] - ci.t, ci.l, ci.r, i, 1));
      }
    }
    I.insert(interval(l[i], r[i], t[i]));
  }
  for (int i = (0); i < (N); ++i)
    E.push_back(event(f[i] ? (m[i] + f[i] - 1) / f[i] : 0, i, 0, 0, 0));
}
void sweep() {
  sort(E.begin(), E.end());
  for (int i = (0); i < (N); ++i) {
    update(rate, i, f[i]);
    if (f[i] == 0) m[i] = 0;
  }
  for (auto &e : E) {
    if (e.type == 0) {
      update(rate, e.x, -f[e.x]);
      update(top, e.x, +m[e.x]);
    } else {
      sol[e.qid] += e.delta * query(rate, e.x, e.y) + query(top, e.x, e.y);
    }
  }
}
int main(void) {
  scanf("%d", &N);
  for (int i = (0); i < (N); ++i) scanf("%d%d%d", &s[i], &m[i], &f[i]);
  scanf("%d", &M);
  for (int i = (0); i < (M); ++i) scanf("%d%d%d", &t[i], &l[i], &r[i]);
  build_events();
  sweep();
  for (int i = (0); i < (M); ++i) cout << sol[i] << endl;
  return 0;
}
