#include <bits/stdc++.h>
using namespace std;
const int up = 100000;
int n, m, s[100050], mx[100050], rp[100050];
int b[100050], c[100050];
long long sum[100050];
pair<long long, long long> operator+(const pair<long long, long long> &a,
                                     const pair<long long, long long> &b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
struct Presidentree {
  bool op;
  int rt[100050], ls[100050 * 20], rs[100050 * 20], node;
  long long val[100050 * 20], sum[100050 * 20];
  void modify(int &x, int las, int l, int r, int pos, int p) {
    x = ++node;
    ls[x] = ls[las];
    rs[x] = rs[las];
    val[x] = val[las] + rp[p];
    sum[x] = sum[las] + mx[p] - (op ? 0 : s[p]);
    if (l == r) return;
    int mid = (l + r) >> 1;
    if (pos <= mid)
      modify(ls[x], ls[las], l, mid, pos, p);
    else
      modify(rs[x], rs[las], mid + 1, r, pos, p);
  }
  pair<long long, long long> query(int a, int b, int l, int r, int L, int R) {
    if (!a) return make_pair(0, 0);
    if (L <= l && r <= R) return make_pair(val[a] - val[b], sum[a] - sum[b]);
    int mid = (l + r) >> 1;
    pair<long long, long long> ans = make_pair(0, 0);
    if (L <= mid) ans = ans + query(ls[a], ls[b], l, mid, L, R);
    if (R > mid) ans = ans + query(rs[a], rs[b], mid + 1, r, L, R);
    return ans;
  }
} T[2];
struct Node {
  int l, r, v;
  Node(int _l = 0, int _r = 0, int _v = 0) : l(_l), r(_r), v(_v) {}
  bool operator<(const Node &a) const { return l < a.l; }
};
set<Node> S;
set<Node>::iterator split(int p) {
  set<Node>::iterator it = S.lower_bound(Node(p));
  if (it != S.end() && it->l == p) return it;
  it--;
  int l = it->l, r = it->r, v = it->v;
  S.erase(it);
  S.insert(Node(l, p - 1, v));
  it = S.lower_bound(Node(l, p - 1, v));
  return S.insert(Node(p, r, v)).first;
}
long long ask(int t, int x, int y) {
  set<Node>::iterator R = split(y + 1), L = split(x);
  long long ans = sum[y] - sum[x - 1];
  for (set<Node>::iterator it = L; it != R; it++) {
    pair<long long, long long> res;
    if (it->v == 0)
      res = T[0].query(T[0].rt[it->r], T[0].rt[it->l - 1], 0, up + 1,
                       min(up + 1, t - it->v + 1), up + 1);
    else
      res = T[1].query(T[1].rt[it->r], T[1].rt[it->l - 1], 0, up + 1,
                       min(up + 1, t - it->v + 1), up + 1);
    ans += 1ll * res.first * (t - it->v) - 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], &mx[i], &rp[i]);
    sum[i] = sum[i - 1] + (long long)mx[i];
    if (rp[i] == 0)
      b[i] = c[i] = up + 1;
    else {
      b[i] = (mx[i] - s[i]) / rp[i] + ((mx[i] - s[i]) % rp[i] > 0);
      c[i] = mx[i] / rp[i] + (mx[i] % rp[i] > 0);
    }
  }
  T[0].op = 0;
  T[1].op = 1;
  for (int i = 1; i <= n; i++)
    T[0].modify(T[0].rt[i], T[0].rt[i - 1], 0, up + 1, b[i], i);
  for (int i = 1; i <= n; i++)
    T[1].modify(T[1].rt[i], T[1].rt[i - 1], 0, up + 1, c[i], i);
  S.insert(Node(1, n, 0));
  S.insert(Node(n + 1, n + 1, 0));
  scanf("%d", &m);
  while (m--) {
    int t, l, r;
    scanf("%d%d%d", &t, &l, &r);
    cout << ask(t, l, r) << '\n';
  }
  return 0;
}
