#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1000000000")
using namespace std;
const bool db = false;
vector<pair<int, int> > t[4 * 100010];
vector<long long> suff[4 * 100010], pref[4 * 100010];
int last[4 * 100010];
int n, q;
int S[100010], M[100010], RN[100010];
int I[100010], T, X, Y;
void build(int v, int l, int r) {
  suff[v].resize(r - l + 1);
  pref[v].resize(r - l + 1);
  t[v].resize(r - l + 1);
  if (l != r) {
    int m = (l + r) / 2;
    build(v + v, l, m);
    build(v + v + 1, m + 1, r);
    merge(t[v + v].begin(), t[v + v].end(), t[v + v + 1].begin(),
          t[v + v + 1].end(), t[v].begin());
  } else {
    t[v][0] = make_pair(I[l], l);
  }
  pref[v][0] = M[t[v][0].second];
  suff[v][0] = RN[t[v][0].second];
  for (int i = 1; i < t[v].size(); ++i) {
    pref[v][i] = pref[v][i - 1] + M[t[v][i].second];
    suff[v][i] = suff[v][i - 1] + RN[t[v][i].second];
  }
}
long long go(int v, int l, int r, int dat) {
  dat -= last[v];
  last[v] += dat;
  int it = upper_bound(t[v].begin(), t[v].end(), make_pair(dat, 1000000007)) -
           t[v].begin();
  if (it == t[v].size()) {
    return pref[v].back();
  }
  if (it == 0) {
    return suff[v].back() * 1LL * dat;
  }
  return pref[v][it - 1] + (suff[v][r - l] - suff[v][it - 1]) * 1LL * dat;
}
long long query(int v, int L, int R, int l, int r, int dat) {
  if (l > R || r < L) return 0LL;
  if (l <= L && R <= r && last[v]) return go(v, L, R, dat);
  if (L == R) {
    last[v] = dat;
    return min(0LL + M[t[v][0].second],
               S[t[v][0].second] + dat * 1LL * RN[t[v][0].second]);
  }
  int M = (L + R) >> 1;
  last[v + v] = max(last[v], last[v + v]);
  last[v + v + 1] = max(last[v + v + 1], last[v]);
  if (l <= L && R <= r)
    last[v] = dat;
  else
    last[v] = 0;
  return query(v + v, L, M, l, r, dat) + query(v + v + 1, M + 1, R, l, r, dat);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d%d", &S[i], &M[i], &RN[i]);
    if (RN[i] == 0) {
      I[i] = 1000000007;
      continue;
    }
    I[i] = (M[i] + RN[i] - 1) / RN[i];
  }
  build(1, 1, n);
  scanf("%d", &q);
  while (q-- > 0) {
    scanf("%d%d%d", &T, &X, &Y);
    printf("%lld\n", query(1, 1, n, X, Y, T));
  }
  getchar();
  getchar();
  return 0;
}
