#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int inf = 1000000000;
struct ST {
  int l, r, t;
} t[N << 2];
struct node {
  int s, m, r, t;
  friend bool operator<(node a, node b) { return a.t < b.t; }
  node() {}
  node(int s, int m, int r, int t) : s(s), m(m), r(r), t(t) {}
} p[20][N];
int n, c, L, R, T;
int ss[N], mm[N], rr[N];
long long sm[20][N], sr[20][N];
void update(int k) {
  if (t[k << 1].t == t[k << 1 | 1].t)
    t[k].t = t[k << 1].t;
  else
    t[k].t = -1;
}
void pushdown(int k) {
  if (t[k].t >= 0) t[k << 1].t = t[k << 1 | 1].t = t[k].t;
}
void build(int k, int l, int r, int d) {
  int i, j, z;
  t[k].t = -2;
  t[k].l = l;
  t[k].r = r;
  if (l == r) {
    if (!rr[l])
      z = inf;
    else
      z = (mm[l] + rr[l] - 1) / rr[l];
    p[d][l] = node(ss[l], mm[l], rr[l], z);
    sm[d][l] = sm[d][l - 1] + 1ll * mm[l];
    sr[d][l] = sr[d][l - 1] + 1ll * rr[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(k << 1, l, mid, d + 1);
  build(k << 1 | 1, mid + 1, r, d + 1);
  z = i = l;
  j = mid + 1;
  while (i <= mid && j <= r) {
    if (p[d + 1][i] < p[d + 1][j])
      p[d][z++] = p[d + 1][i++];
    else
      p[d][z++] = p[d + 1][j++];
  }
  while (i <= mid) p[d][z++] = p[d + 1][i++];
  while (j <= r) p[d][z++] = p[d + 1][j++];
  for (i = l; i <= r; i++) sm[d][i] = sm[d][i - 1] + 1ll * p[d][i].m;
  for (i = l; i <= r; i++) sr[d][i] = sr[d][i - 1] + 1ll * p[d][i].r;
  update(k);
}
int calc(int p, int t) {
  return min(1ll * mm[p], 1ll * t * rr[p] + 1ll * ss[p]);
}
long long query(int k, int L, int R, int c, int d) {
  long long res = 0;
  int i, j;
  if (L <= t[k].l && t[k].r <= R && t[k].t != -1) {
    if (t[k].t == -2) {
      for (i = t[k].l; i <= t[k].r; i++) res += calc(i, c);
    } else {
      node w;
      w.t = c - t[k].t;
      j = upper_bound(p[d] + t[k].l, p[d] + t[k].r + 1, w) - p[d] - 1;
      res = sm[d][j] - sm[d][t[k].l - 1] +
            1ll * (c - t[k].t) * (sr[d][t[k].r] - sr[d][j]);
    }
    t[k].t = c;
    return res;
  }
  pushdown(k);
  int mid = (t[k].l + t[k].r) >> 1;
  if (L <= mid) res += query(k << 1, L, R, c, d + 1);
  if (R > mid) res += query(k << 1 | 1, L, R, c, d + 1);
  update(k);
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d%d", &ss[i], &mm[i], &rr[i]);
  build(1, 1, n, 0);
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d%d", &c, &L, &R);
    printf("%I64d\n", query(1, L, R, c, 0));
  }
  return 0;
}
