#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
const int inf = 2e9;
int s[maxn], m[maxn], r[maxn], t[maxn], vis[maxn << 2];
int T[20][maxn];
long long pre[20][maxn], v[20][maxn];
struct in {
  int m, r, t;
  in() {}
  in(int mm, int rr, int tt) : m(mm), r(rr), t(tt) {}
  bool friend operator<(in w, in v) { return w.t < v.t; }
} fcy[maxn];
void build(int dep, int Now, int L, int R) {
  for (int i = L; i <= R; i++) fcy[i] = in(m[i], r[i], t[i]);
  sort(fcy + L, fcy + R + 1);
  for (int i = L; i <= R; i++) {
    T[dep][i] = fcy[i].t;
    pre[dep][i] = fcy[i].m;
    v[dep][i] = fcy[i].r;
    if (i > L) {
      pre[dep][i] += pre[dep][i - 1];
      v[dep][i] += v[dep][i - 1];
    }
  }
  if (L == R) {
    vis[Now] = 0;
    return;
  }
  vis[Now] = -1;
  int Mid = (L + R) >> 1;
  build(dep + 1, Now << 1, L, Mid);
  build(dep + 1, Now << 1 | 1, Mid + 1, R);
}
long long query(int dep, int Now, int L, int R, int ql, int qr, int times) {
  if (vis[Now] == 0) {
    vis[Now] = times;
    if (s[L] + 1LL * times * r[L] >= m[L]) return 1LL * m[L];
    return 1LL * s[L] + times * r[L];
  }
  if (ql <= L && qr >= R && vis[Now] > 0) {
    int tp = times - vis[Now];
    int p = upper_bound(T[dep] + L, T[dep] + R + 1, tp) - T[dep];
    p--;
    long long res = 0;
    if (p >= L) res = pre[dep][p];
    long long vd = v[dep][R];
    if (p >= L) vd -= v[dep][p];
    res += vd * tp;
    vis[Now] = times;
    return res;
  }
  if (vis[Now] >= 0) vis[Now << 1] = vis[Now << 1 | 1] = vis[Now];
  int Mid = (L + R) >> 1;
  long long res = 0;
  if (ql <= Mid) res += query(dep + 1, Now << 1, L, Mid, ql, qr, times);
  if (qr > Mid) res += query(dep + 1, Now << 1 | 1, Mid + 1, R, ql, qr, times);
  if (vis[Now << 1] == vis[Now << 1 | 1])
    vis[Now] = vis[Now << 1];
  else
    vis[Now] = -1;
  return res;
}
int main() {
  int N, M, ts, L, R;
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d%d%d", &s[i], &m[i], &r[i]);
    if (!r[i])
      t[i] = inf;
    else
      t[i] = m[i] / r[i] + (m[i] % r[i] ? 1 : 0);
  }
  build(1, 1, 1, N);
  scanf("%d", &M);
  for (int i = 1; i <= M; i++) {
    scanf("%d%d%d", &ts, &L, &R);
    long long ans = query(1, 1, 1, N, L, R, ts);
    printf("%lld\n", ans);
  }
  return 0;
}
