#include <bits/stdc++.h>
inline char nc() {
  static char buf[1000003], *p1 = buf + 1000003, *p2 = buf + 1000003;
  if (p1 == p2) {
    p1 = buf;
    p2 = buf + fread(buf, 1, 1000003, stdin);
    if (p1 == p2) return -1;
  }
  return *p1++;
}
inline void read(int &x) {
  x = 0;
  char ch = nc();
  bool flag = 0;
  while (!isdigit(ch)) {
    if (ch == '-') flag = 1;
    ch = nc();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + (ch ^ '0');
    ch = nc();
  }
  if (flag) x = -x;
}
const int MAXN = 1e5 + 5;
int n, q;
int s[MAXN], m[MAXN], d[MAXN];
std::vector<std::pair<int, int> > add[MAXN], del[MAXN];
long long ans[MAXN];
long long sd[MAXN * 18], sm[MAXN * 18];
int lc[MAXN * 18], rc[MAXN * 18], tot;
inline void insert(int prev, int &v, int l, int r, int p, int m, int d) {
  sd[v = ++tot] = sd[prev] + d;
  sm[v] = sm[prev] + m;
  lc[v] = lc[prev];
  rc[v] = rc[prev];
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (p <= mid)
    insert(lc[prev], lc[v], l, mid, p, m, d);
  else
    insert(rc[prev], rc[v], mid + 1, r, p, m, d);
}
inline long long query(int x, int y, int l, int r, int L, int R, int o) {
  if (L > R) return 0;
  if (l == L && r == R) return o == 0 ? sd[y] - sd[x] : sm[y] - sm[x];
  int mid = (l + r) >> 1;
  if (R <= mid) return query(lc[x], lc[y], l, mid, L, R, o);
  if (L > mid) return query(rc[x], rc[y], mid + 1, r, L, R, o);
  return query(lc[x], lc[y], l, mid, L, mid, o) +
         query(rc[x], rc[y], mid + 1, r, mid + 1, R, o);
}
int rt[MAXN];
struct Node {
  int x, st, id;
  Node(int x = 0, int st = 0, int id = 0) : x(x), st(st), id(id) {}
  bool operator<(const Node &t) const { return x < t.x; }
};
std::set<Node> st;
std::vector<int> S;
inline void upd(std::set<Node>::iterator p, int now) {
  if (p == st.begin()) return;
  if (p->st == now) return;
  int len = p->x - prev(p)->x, L = p->st, R = now - 1;
  int ps = std::lower_bound(S.begin(), S.end(), len) - S.begin();
  ans[p->id] += query(rt[L - 1], rt[R], 1, ((int)S.size()), 1, ps, 1);
  ans[p->id] +=
      query(rt[L - 1], rt[R], 1, ((int)S.size()), ps + 1, ((int)S.size()), 0) *
      len;
  Node tmp = *p;
  tmp.st = now;
  st.erase(p);
  st.insert(tmp);
}
inline void insert(int x, int now, int id) {
  auto p = st.lower_bound(Node(x));
  if (p != st.end()) upd(p, now);
  st.insert(Node(x, now, id));
}
inline void erase(int x, int now, int id) {
  auto p = st.upper_bound(Node(x));
  if (p != st.end()) upd(p, now);
  p = st.lower_bound(Node(x));
  upd(p, now);
  st.erase(st.lower_bound(Node(x)));
}
int main() {
  read(n);
  for (int i = 1; i <= n; ++i) {
    read(s[i]);
    read(m[i]);
    read(d[i]);
    if (d[i]) S.emplace_back(m[i] / d[i]);
  }
  std::sort(S.begin(), S.end());
  S.erase(std::unique(S.begin(), S.end()), S.end());
  for (int i = 1; i <= n; ++i) {
    if (d[i])
      insert(rt[i - 1], rt[i], 1, ((int)S.size()),
             std::lower_bound(S.begin(), S.end(), m[i] / d[i]) - S.begin() + 1,
             m[i], d[i]);
    else
      rt[i] = rt[i - 1];
  }
  read(q);
  for (int i = 1; i <= q; ++i) {
    int t, l, r;
    read(t);
    read(l);
    read(r);
    add[l].emplace_back(t, i);
    del[r + 1].emplace_back(t, i);
  }
  for (int i = 1; i <= n + 1; ++i) {
    for (auto x : add[i]) {
      insert(x.first, i, x.second);
    }
    for (auto x : del[i]) {
      erase(x.first, i, x.second);
    }
    if (i <= n && !st.empty()) {
      Node p = *st.begin();
      ans[p.id] += std::min(1ll * m[i], 1ll * p.x * d[i] + s[i]);
      st.erase(p);
      p.st = i + 1;
      st.insert(p);
    }
  }
  for (int i = 1; i <= q; ++i) printf("%lld\n", ans[i]);
  return 0;
}
