#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, m, len[maxn << 2];
bool first[maxn << 2];
long long mm[maxn], rr[maxn], ss[maxn], last[maxn << 2];
vector<long long> summ[maxn << 2], sumr[maxn << 2];
vector<int> tree[maxn << 2];
bool cmp(int a, int b) { return mm[a] * rr[b] < mm[b] * rr[a]; }
void build(int cur, int l, int r) {
  len[cur] = 0;
  first[cur] = true, last[cur] = -1;
  tree[cur].clear();
  tree[cur].push_back(0);
  for (int i = l; i <= r; i++)
    if (mm[i] != 0 && rr[i] != 0) tree[cur].push_back(i), len[cur]++;
  sort(tree[cur].begin() + 1, tree[cur].end(), cmp);
  summ[cur].clear();
  sumr[cur].clear();
  summ[cur].push_back(0);
  sumr[cur].push_back(0);
  long long sr = 0, sm = 0;
  for (int i = 1; i <= len[cur]; i++) {
    sr += rr[tree[cur][i]];
    sm += mm[tree[cur][i]];
    sumr[cur].push_back(sr);
    summ[cur].push_back(sm);
  }
  if (l != r) {
    build((cur << 1), l, ((l + r) >> 1));
    build((cur << 1 | 1), ((l + r) >> 1) + 1, r);
  }
}
int find(int cur, long long t) {
  int l = 1, r = len[cur];
  while (l <= r) {
    if (t * rr[tree[cur][((l + r) >> 1)]] >= mm[tree[cur][((l + r) >> 1)]])
      l = ((l + r) >> 1) + 1;
    else
      r = ((l + r) >> 1) - 1;
  }
  return l - 1;
}
long long ask(int cur, int l, int r, long long t) {
  if (l == r && first[cur]) {
    long long ret = min(mm[l], t * rr[l] + ss[l]);
    ss[l] = 0, first[cur] = false;
    return ret;
  }
  if (last[cur] != -1) {
    long long delta = t - last[cur];
    int mid = find(cur, delta);
    long long ret = 0;
    ret += summ[cur][mid];
    ret += (sumr[cur][len[cur]] - sumr[cur][mid]) * delta;
    return ret;
  }
  long long ret = 0;
  ret += ask((cur << 1), l, ((l + r) >> 1), t);
  ret += ask((cur << 1 | 1), ((l + r) >> 1) + 1, r, t);
  return ret;
}
void down(int cur) {
  if (last[cur] != -1) {
    first[(cur << 1)] = first[(cur << 1 | 1)] = false;
    last[(cur << 1)] = last[(cur << 1 | 1)] = last[cur];
    last[cur] = -1;
  }
}
long long query(int cur, int l, int r, int ql, int qr, long long t) {
  if (ql <= l && r <= qr) {
    long long ret = ask(cur, l, r, t);
    first[cur] = false, last[cur] = t;
    return ret;
  }
  down(cur);
  long long ret = 0;
  if (ql <= ((l + r) >> 1))
    ret += query((cur << 1), l, ((l + r) >> 1), ql, qr, t);
  if (qr > ((l + r) >> 1))
    ret += query((cur << 1 | 1), ((l + r) >> 1) + 1, r, ql, qr, t);
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d%I64d%I64d", &ss[i], &mm[i], &rr[i]);
  build(1, 1, n);
  scanf("%d", &m);
  int qq = 0;
  while (m--) {
    ++qq;
    int t, l, r;
    scanf("%d%d%d", &t, &l, &r);
    printf("%I64d\n", query(1, 1, n, l, r, t));
  }
  return 0;
}
