#include <bits/stdc++.h>
template <typename T>
void read(T &x);
template <typename T>
void read(T &x, T &y);
template <typename T>
void read(T &x, T &y, T &z);
template <typename T>
void write(T x);
template <typename T>
void writeC(T x);
template <typename T>
void writeN(T x);
const int lim = 1e5 + 2;
int n, s[100005], m[100005], rg[100005], q;
long long ans[100005];
struct LordTirek {
  long long sum[100005];
  int magic(int x) { return x & -x; }
  void add(int x, int y) {
    while (x <= lim) {
      sum[x] += y;
      x += magic(x);
    }
  }
  long long query(int x) {
    long long ans = 0;
    while (x > 0) {
      ans += sum[x];
      x -= magic(x);
    }
    return ans;
  }
} A, B;
struct data {
  int x, det, id;
};
namespace scanner {
std::vector<data> qry[100005];
void Add(int l, int r, int x, int id) {
  x = std::min(x, lim);
  qry[r].push_back(data({x, 1, id}));
  qry[l - 1].push_back(data({x, -1, id}));
}
void work() {
  for (int i = 1; i <= n; ++i) {
    if (rg[i]) {
      B.add(m[i] / rg[i] + 1, rg[i]);
      A.add(m[i] / rg[i] + 1, m[i]);
    }
    for (auto x : qry[i]) {
      long long val = A.query(x.x) + (B.query(lim) - B.query(x.x)) * x.x;
      ans[x.id] += x.det * val;
    }
  }
}
}  // namespace scanner
std::set<std::pair<std::pair<int, int>, int> > S;
void pushall(int l, int r, int x, int i) {
  std::stack<std::pair<std::pair<int, int>, int> > inc, stk;
  auto p =
      std::prev(S.upper_bound(std::make_pair(std::make_pair(l, 1e9), 1e9)));
  while (1) {
    if (p == S.end()) break;
    int L = (*p).first.first, R = (*p).first.second, w = (*p).second;
    if (L > r) break;
    int l1 = std::max(L, l), r1 = std::min(R, r);
    if (l1 <= r1) {
      if (w) {
        scanner::Add(l1, r1, x - w, i);
      } else
        ans[i] += std::min((long long)x * rg[l1] + s[l1], (long long)m[l1]);
    }
    stk.push(*p);
    if (L < l) inc.push(std::make_pair(std::make_pair(L, l - 1), w));
    if (r < R) inc.push(std::make_pair(std::make_pair(r + 1, R), w));
    p++;
  }
  while (!stk.empty()) {
    S.erase(stk.top());
    stk.pop();
  }
  while (!inc.empty()) {
    S.insert(inc.top());
    inc.pop();
  }
  S.insert(std::make_pair(std::make_pair(l, r), x));
}
signed main() {
  read(n);
  for (int i = (1); i <= (n); ++i) {
    read(s[i], m[i], rg[i]);
  }
  for (int i = (1); i <= (n); ++i)
    S.insert(std::make_pair(std::make_pair(i, i), 0));
  S.insert(std::make_pair(std::make_pair(0, 0), 0));
  S.insert(std::make_pair(std::make_pair(n + 1, n + 1), 0));
  read(q);
  for (int i = (1); i <= (q); ++i) {
    int l, r, t;
    read(t, l, r);
    pushall(l, r, t, i);
  }
  scanner::work();
  for (int i = 1; i <= q; ++i) printf("%lld\n", ans[i]);
  return 0;
}
template <typename T>
void read(T &x) {
  x = 0;
  char c = getchar();
  T flag = 1;
  while (c < '0' || c > '9') {
    if (c == '-') flag = -flag;
    c = getchar();
  }
  while ('0' <= c && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= flag;
}
template <typename T>
void read(T &x, T &y) {
  read(x);
  read(y);
}
template <typename T>
void read(T &x, T &y, T &z) {
  read(x);
  read(y);
  read(z);
}
template <typename T>
void writeC(T x) {
  if (x < 0) x = ~x + 1, putchar('-');
  if (x > 9) writeC(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
void write(T x) {
  writeC(x);
  putchar(' ');
}
template <typename T>
void writeN(T x) {
  writeC(x);
  puts("");
}
