#include <bits/stdc++.h>
using namespace std;
template <class T>
inline int sz(const T& v) {
  return v.size();
}
const int N = 100000;
const int BLOCK = 320;
const int INF = 1000000000;
int s[N], m[N], r[N];
int lastCollects[N];
struct Block {
  int fromIndex;
  int toIndex;
  int lastCollect;
  bool canTakeAll;
  vector<pair<int, int>> times;
  vector<pair<long long, long long>> mana;
  inline void build() {
    lastCollect = -1;
    canTakeAll = false;
    times.reserve(toIndex - fromIndex);
    long long sumR = 0;
    long long sumM = 0;
    for (int i = (fromIndex); i < (toIndex); ++i) {
      int t = r[i] != 0 ? (m[i] + r[i] - 1) / r[i] : INF;
      times.emplace_back(t, i);
      sumR += r[i];
    }
    sort(times.begin(), times.end());
    mana.reserve(sz(times) + 1);
    mana.emplace_back(sumM, sumR);
    for (auto p : times) {
      sumM += m[p.second];
      sumR -= r[p.second];
      mana.emplace_back(sumM, sumR);
    }
  }
  inline long long getAll(int t) {
    long long ans = 0;
    if (!canTakeAll) {
      ans += getSegment(t, fromIndex, toIndex, true);
    } else {
      int index = lower_bound(times.begin(), times.end(),
                              make_pair(t - lastCollect, INF)) -
                  times.begin();
      ans += mana[index].first + 1LL * mana[index].second * (t - lastCollect);
    }
    canTakeAll = true;
    lastCollect = t;
    return ans;
  }
  inline long long getSegment(int t, int ql, int qr, bool force = false) {
    if (!force && ql <= fromIndex && toIndex <= qr) {
      return getAll(t);
    }
    if (toIndex <= ql || qr <= fromIndex) {
      return 0;
    }
    long long ans = 0;
    for (int i = max(ql, fromIndex); i < min(qr, toIndex); ++i) {
      lastCollects[i] = max(lastCollects[i], lastCollect);
      if (lastCollects[i] == -1) {
        ans += min((long long)m[i], s[i] + 1LL * r[i] * t);
      } else {
        ans += min((long long)m[i], 1LL * r[i] * (t - lastCollects[i]));
      }
      lastCollects[i] = t;
    }
    canTakeAll = false;
    return ans;
  }
};
int main() {
  std::ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < (n); ++i) {
    cin >> s[i] >> m[i] >> r[i];
    lastCollects[i] = -1;
  }
  int nBlocks = (n + BLOCK - 1) / BLOCK;
  vector<Block> blocks(nBlocks);
  for (int i = 0; i < nBlocks; ++i) {
    blocks[i].fromIndex = i * BLOCK;
    blocks[i].toIndex = min((i + 1) * BLOCK, n);
    blocks[i].build();
  }
  int m;
  cin >> m;
  for (int i = 0; i < (m); ++i) {
    int t, l, r;
    cin >> t >> l >> r;
    long long ans = 0;
    --l;
    for (Block& b : blocks) {
      ans += b.getSegment(t, l, r);
    }
    cout << ans << '\n';
  }
  cout.flush();
  return 0;
}
