#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5;
const long long linf = 1e18 + 5;
const int N = 1e5 + 5;
const int K = 1000;
const int T = N / K + 5;
int n, q, st[N], ma[N], re[N], b[T], e[T], last[T], lasti[N], rtime[N],
    _time[N], suml[N], sumr[N];
bool is_zero[T];
int query(int x, int t, int l, int r) {
  if (r < b[x] or l > e[x]) return 0;
  if (l <= b[x] and e[x] <= r and is_zero[x]) {
    int dif = t - last[x];
    last[x] = t;
    int ind = lower_bound(_time + b[x], _time + e[x] + 1, dif) - _time;
    int ans = 0;
    if (ind <= e[x]) ans += sumr[ind] * dif;
    if (ind - 1 >= b[x]) ans += suml[ind - 1];
    return ans;
  }
  int ans = 0;
  l = max(l, b[x]);
  r = min(r, e[x]);
  for (int i = l; i <= r; i++) {
    ans += min((long long)ma[i],
               st[i] + (long long)(t - max(last[x], lasti[i])) * re[i]);
    lasti[i] = t;
    st[i] = 0;
  }
  is_zero[x] = l <= b[x] and e[x] <= r;
  if (is_zero[x]) last[x] = t;
  return ans;
}
int main() {
  ios ::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> st[i] >> ma[i] >> re[i];
  for (int i = 1; (i - 1) * K + 1 <= n; i++) {
    b[i] = (i - 1) * K + 1;
    e[i] = min(i * K, n);
    for (int j = b[i]; j <= e[i]; j++) {
      rtime[j] = re[j] ? ma[j] / re[j] : inf;
      _time[j] = rtime[j];
    }
    sort(_time + b[i], _time + e[i] + 1);
    for (int j = b[i]; j <= e[i]; j++) {
      int ind = lower_bound(_time + b[i], _time + e[i] + 1, rtime[j]) - _time;
      suml[ind] += ma[j];
      sumr[ind] += re[j];
    }
    for (int j = e[i] - 1; j >= b[i]; j--) sumr[j] += sumr[j + 1];
    for (int j = b[i] + 1; j <= e[i]; j++) suml[j] += suml[j - 1];
  }
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int t, l, r;
    cin >> t >> l >> r;
    long long ans = 0;
    for (int i = 1; (i - 1) * K + 1 <= n; i++) ans += query(i, t, l, r);
    cout << ans << '\n';
  }
  return 0;
}
