#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read(register T& t) {
  register T f = 1;
  register char ch = getchar();
  t = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') t = t * 10 + ch - '0', ch = getchar();
  t *= f;
  return t;
}
template <typename T, typename... Args>
inline void read(T& t, Args&... args) {
  read(t);
  read(args...);
}
const long long p = 998244353;
inline long long power(register long long x, register long long k = p - 2) {
  register long long re = 1;
  for (; k; k >>= 1, x = x * x % p)
    if (k & 1) re = re * x % p;
  return re;
}
int n;
long long S[100005], R[100005], K[100005];
struct SGT {
  int lcs, rcs;
  long long Tag;
  vector<int> Arr;
  vector<long long> Sr, Sk;
} v[200005];
int tot;
inline bool cmp(int x, int y) {
  long long tx = K[x] ? (R[x] / K[x] + (R[x] % K[x] > 0)) : 1e18;
  long long ty = K[y] ? (R[y] / K[y] + (R[y] % K[y] > 0)) : 1e18;
  return tx < ty;
}
void build(int l, int r, int& p) {
  p = ++tot;
  for (int i = l; i <= r; i++) v[p].Arr.push_back(i);
  sort(v[p].Arr.begin(), v[p].Arr.end(), cmp);
  long long SumR = 0;
  for (int i : v[p].Arr) v[p].Sr.push_back(SumR += R[i]);
  long long SumK = 0;
  for (int i : v[p].Arr) v[p].Sk.push_back(SumK += K[i]);
  v[p].Tag = -2;
  if (l == r) return;
  build(l, ((l + r) >> 1), v[p].lcs);
  build(((l + r) >> 1) + 1, r, v[p].rcs);
}
void push_down(int l, int r, int p) {
  if (v[p].Tag >= 0) {
    v[v[p].lcs].Tag = v[p].Tag;
    v[v[p].rcs].Tag = v[p].Tag;
  }
}
long long enquire(int l, int r, int p, int nl, int nr, long long T) {
  if (nl <= l && r <= nr && v[p].Tag != -1) {
    if (v[p].Tag == -2) {
      v[p].Tag = T;
      long long ans = 0;
      for (int i = l; i <= r; i++) ans += min(T * K[i] + S[i], R[i]);
      return ans;
    }
    R[0] = T - v[p].Tag;
    K[0] = 1;
    int id = upper_bound(v[p].Arr.begin(), v[p].Arr.end(), 0, cmp) -
             v[p].Arr.begin();
    long long A = 0, B = 0;
    if (id != 0) A = v[p].Sr[id - 1];
    if (id != 0)
      B = (*v[p].Sk.rbegin() - v[p].Sk[id - 1]) * (T - v[p].Tag);
    else
      B = *v[p].Sk.rbegin() * (T - v[p].Tag);
    v[p].Tag = T;
    return A + B;
  }
  push_down(l, r, p);
  long long re = 0;
  if (nl <= ((l + r) >> 1))
    re += enquire(l, ((l + r) >> 1), v[p].lcs, nl, nr, T);
  if (((l + r) >> 1) + 1 <= nr)
    re += enquire(((l + r) >> 1) + 1, r, v[p].rcs, nl, nr, T);
  if (v[v[p].lcs].Tag == v[v[p].rcs].Tag)
    v[p].Tag = v[v[p].lcs].Tag;
  else
    v[p].Tag = -1;
  return re;
}
int main() {
  read(n);
  for (int i = 1; i <= n; i++) read(S[i], R[i], K[i]);
  int root;
  build(1, n, root);
  int Q;
  read(Q);
  while (Q--) {
    int T, l, r;
    read(T, l, r);
    printf("%lld\n", enquire(1, n, 1, l, r, T));
  }
  return 0;
}
