#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
const int inf = 0x3f3f3f3f;
int n, m, S[maxn], M[maxn], R[maxn], b[maxn], c[maxn];
long long sumM[maxn];
inline pair<long long, long long> operator+(pair<long long, long long> a,
                                            pair<long long, long long> b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
struct CM {
  int op, rt[maxn], ls[maxn * 20], rs[maxn * 20], sz;
  long long val[maxn * 20], sum[maxn * 20], w[maxn * 20];
  void update(int &x, int y, int l, int r, int pos, int p) {
    x = ++sz;
    ls[x] = ls[y];
    rs[x] = rs[y];
    val[x] = val[y] + R[p];
    sum[x] = sum[y] + M[p] - ((op == 0) ? S[p] : 0);
    if (l == r) return;
    int mid = (l + r) >> 1;
    if (pos <= mid)
      update(ls[x], ls[y], l, mid, pos, p);
    else
      update(rs[x], rs[y], mid + 1, r, pos, p);
  }
  pair<long long, long long> query(int u, int v, int L, int R, int l, int r) {
    if (L <= l && r <= R) return make_pair(val[v] - val[u], sum[v] - sum[u]);
    int mid = (l + r) >> 1;
    pair<long long, long long> ans = make_pair(0, 0);
    if (L <= mid) ans = ans + query(ls[u], ls[v], L, R, l, mid);
    if (R > mid) ans = ans + query(rs[u], rs[v], L, R, mid + 1, r);
    return ans;
  }
} T[2];
struct node {
  int l, r, val;
  node(int _l = 0, int _r = 0, int _val = 0) : l(_l), r(_r), val(_val) {}
};
set<node> s;
inline bool operator<(const node &a, const node &b) { return a.l < b.l; }
inline set<node>::iterator split(int x) {
  set<node>::iterator it = s.lower_bound(node(x));
  if (it != s.end() && it->l == x) return it;
  it--;
  int l = it->l, r = it->r, val = it->val;
  s.erase(it);
  s.insert(node(l, x - 1, val));
  return s.insert(node(x, r, val)).first;
}
inline long long ask(int t, int x, int y) {
  set<node>::iterator R = split(y + 1), L = split(x);
  int l, r, val;
  long long ans = sumM[y] - sumM[x - 1];
  pair<long long, long long> res;
  for (set<node>::iterator it = L; it != R; it++) {
    l = it->l;
    r = it->r;
    val = it->val;
    if (val == 0)
      res = T[0].query(T[0].rt[l - 1], T[0].rt[r], min(100001, t - val + 1),
                       100001, 0, 100001);
    else
      res = T[1].query(T[1].rt[l - 1], T[1].rt[r], min(100001, t - val + 1),
                       100001, 0, 100001);
    ans += res.first * (t - val) - res.second;
  }
  s.erase(L, R);
  s.insert(node(x, y, t));
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d%d", &S[i], &M[i], &R[i]);
  for (int i = 1; i <= n; i++) {
    b[i] = (R[i] == 0) ? 100001
                       : (M[i] - S[i]) / R[i] + ((M[i] - S[i]) % R[i] > 0);
    c[i] = (R[i] == 0) ? 100001 : M[i] / R[i] + (M[i] % R[i] > 0);
    sumM[i] = sumM[i - 1] + M[i];
  }
  T[0].op = 0;
  T[1].op = 1;
  for (int i = 1; i <= n; i++)
    T[0].rt[i] = T[0].rt[i - 1],
    T[0].update(T[0].rt[i], T[0].rt[i], 0, 100001, b[i], i);
  for (int i = 1; i <= n; i++)
    T[1].rt[i] = T[1].rt[i - 1],
    T[1].update(T[1].rt[i], T[1].rt[i], 0, 100001, c[i], i);
  s.insert(node(1, n, 0));
  s.insert(node(n + 1, n + 1, 0));
  scanf("%d", &m);
  int t, l, r;
  while (m--) {
    scanf("%d%d%d", &t, &l, &r);
    printf("%I64d\n", ask(t, l, r));
  }
  return 0;
}
