#include <bits/stdc++.h>
using namespace std;
using LL = long long;
namespace _buff {
const size_t BUFF = 1 << 19;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
  if (ib == ie) {
    ib = ibuf;
    ie = ibuf + fread(ibuf, 1, BUFF, stdin);
  }
  return ib == ie ? -1 : *ib++;
}
}  // namespace _buff
LL read() {
  using namespace _buff;
  LL ret = 0;
  bool pos = true;
  char c = getc();
  for (; (c < '0' || c > '9') && c != '-'; c = getc()) {
    assert(~c);
  }
  if (c == '-') {
    pos = false;
    c = getc();
  }
  for (; c >= '0' && c <= '9'; c = getc()) {
    ret = (ret << 3) + (ret << 1) + (c ^ 48);
  }
  return pos ? ret : -ret;
}
const size_t N = 1e5 + 5;
int s[N], m[N], r[N];
struct Node {
  int tag = -1;
  vector<tuple<int, LL, LL> > vc;
  Node() {}
} t[N << 2];
void update(int x, int tl, int tr, int val) {
  t[x].tag = val;
  if (val < 0) return;
  Node &n = t[x];
  if (n.vc.empty()) {
    n.vc.emplace_back(0, 0, 0);
    for (int i = tl; i < tr; ++i) {
      n.vc.emplace_back(r[i] ? m[i] / r[i] : INT_MAX, m[i], r[i]);
    }
    sort(n.vc.begin(), n.vc.end());
    for (auto it = n.vc.begin() + 1; it != n.vc.end(); ++it) {
      get<1>(*it) += get<1>(*(it - 1));
      get<2>(*it) += get<2>(*(it - 1));
    }
  }
}
void pushdown(int x, int tl, int tr) {
  if (t[x].tag >= 0) {
    int mid = (tl + tr) >> 1;
    update(((x) << 1), tl, mid, t[x].tag);
    update(((x) << 1 | 1), mid, tr, t[x].tag);
  }
}
LL calc(int x, int tl, int tr, int cur) {
  Node &n = t[x];
  assert(!n.vc.empty());
  auto bnd =
      lower_bound(n.vc.begin(), n.vc.end(), make_tuple(cur - n.tag, 0, 0)) - 1;
  LL ret = get<1>(*bnd) + (cur - n.tag) * (get<2>(n.vc.back()) - get<2>(*bnd));
  update(x, tl, tr, cur);
  return ret;
}
void pushup(int x, int tl, int tr) {
  if (t[((x) << 1)].tag != t[((x) << 1 | 1)].tag) {
    t[x].tag = -1;
  } else {
    update(x, tl, tr, t[((x) << 1)].tag);
  }
}
LL query(int x, int tl, int tr, int l, int r, int cur) {
  if (tr <= l || tl >= r) return 0;
  if (l <= tl && tr <= r && t[x].tag >= 0) {
    return calc(x, tl, tr, cur);
  }
  if (tl + 1 == tr) {
    update(x, tl, tr, cur);
    return min((LL)m[tl], s[tl] + (LL)cur * ::r[tl]);
  }
  pushdown(x, tl, tr);
  int mid = (tl + tr) >> 1;
  LL ret = query(((x) << 1), tl, mid, l, r, cur) +
           query(((x) << 1 | 1), mid, tr, l, r, cur);
  pushup(x, tl, tr);
  return ret;
}
int main() {
  int n = read();
  for (int i = 0; i < n; ++i) {
    s[i] = read();
    m[i] = read();
    r[i] = read();
  }
  int m = read();
  while (m--) {
    int t = read(), l = read() - 1, r = read();
    printf("%lld\n", query(1, 0, n, l, r, t));
  }
  return 0;
}
