#include <bits/stdc++.h>
using namespace std;
const int inf = int(1e9);
const double pi = 4 * atan(double(1.0));
const double eps = 1e-9;
const int N = int(1e5) + 100;
struct ponny {
  int s, m, r;
};
struct node {
  int t;
  long long sum, add_a, add_b;
  int h, sz, p, l, r;
};
int root = 0;
set<pair<int, int> > times;
ponny p[N];
int t[N];
node d[N];
vector<int> add[N], del[N];
inline int get_rand() { return (rand() << 16) | rand(); }
inline void push(int v) {
  if (v == 0) {
    return;
  }
  d[v].sum += 1LL * d[v].add_a * d[v].t + d[v].add_b;
  if (d[v].l > 0) {
    d[d[v].l].add_a += d[v].add_a;
    d[d[v].l].add_b += d[v].add_b;
  }
  if (d[v].r > 0) {
    d[d[v].r].add_a += d[v].add_a;
    d[d[v].r].add_b += d[v].add_b;
  }
  d[v].add_a = d[v].add_b = 0;
}
inline void calc(int v) {
  d[v].p = 0;
  d[v].sz = d[d[v].l].sz + d[d[v].r].sz + 1;
  if (d[v].l > 0) {
    d[d[v].l].p = v;
  }
  if (d[v].r > 0) {
    d[d[v].r].p = v;
  }
}
void split(int v, int t, int &l, int &r) {
  push(v);
  if (v == 0) {
    l = r = 0;
    return;
  }
  if (d[v].t < t) {
    split(d[v].r, t, d[v].r, r);
    l = v;
  } else {
    split(d[v].l, t, l, d[v].l);
    r = v;
  }
  calc(v);
}
void split_size(int v, int sz, int &l, int &r) {
  push(v);
  if (v == 0) {
    l = r = 0;
    return;
  }
  if (d[d[v].l].sz + 1 <= sz) {
    split_size(d[v].r, sz - d[d[v].l].sz - 1, d[v].r, r);
    l = v;
  } else {
    split_size(d[v].l, sz, l, d[v].l);
    r = v;
  }
  calc(v);
}
int merge(int l, int r) {
  push(l);
  push(r);
  if (l == 0) {
    return r;
  }
  if (r == 0) {
    return l;
  }
  int res;
  if (d[l].h > d[r].h) {
    d[l].r = merge(d[l].r, r);
    res = l;
  } else {
    d[r].l = merge(l, d[r].l);
    res = r;
  }
  calc(res);
  return res;
}
inline void insert_num(int num) {
  int l, r;
  split(root, d[num].t, l, r);
  root = merge(l, merge(num, r));
}
inline int get_num(int v) {
  int res = d[d[v].l].sz + 1;
  while (d[v].p > 0) {
    int pv = d[v].p;
    if (d[pv].r == v) {
      res += d[d[pv].l].sz + 1;
    }
    v = pv;
  }
  return res;
}
inline void del_num(int num) {
  int n = get_num(num);
  int l, r, tmp;
  split_size(root, n, l, r);
  split_size(l, n - 1, l, tmp);
  assert(tmp == num);
  root = merge(l, r);
}
inline void insert_with_new_diff(int num, int new_diff) {
  if (times.find(make_pair(t[num], num)) != times.begin()) {
    del_num(num);
  }
  d[num].t = new_diff;
  insert_num(num);
}
inline void add_query(int num) {
  set<pair<int, int> >::iterator it = times.upper_bound(make_pair(t[num], num));
  d[num].h = get_rand();
  d[num].sz = 1;
  d[num].add_a = d[num].add_b = d[num].sum = 0;
  d[num].p = d[num].l = d[num].r = 0;
  if (it != times.end()) {
    int next_num = it->second;
    insert_with_new_diff(next_num, it->first - t[num]);
  }
  times.insert(make_pair(t[num], num));
  it = times.find(make_pair(t[num], num));
  if (it == times.begin()) {
    return;
  }
  --it;
  d[num].t = t[num] - it->first;
  insert_num(num);
}
inline void del_query(int num) {
  set<pair<int, int> >::iterator it = times.find(make_pair(t[num], num));
  int add = 0;
  if (it != times.begin()) {
    del_num(num);
    add = d[num].t;
  }
  ++it;
  if (it != times.end()) {
    int next_num = it->second;
    if (add > 0) {
      insert_with_new_diff(next_num, d[next_num].t + add);
    } else {
      del_num(next_num);
    }
  }
  times.erase(make_pair(t[num], num));
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d %d", &p[i].s, &p[i].m, &p[i].r);
  }
  int m;
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    int l, r;
    scanf("%d %d %d", &t[i], &l, &r);
    --l;
    --r;
    add[l].push_back(i);
    del[r].push_back(i);
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < int((add[i]).size()); ++j) {
      add_query(add[i][j]);
    }
    if (!times.empty()) {
      int first = times.begin()->second;
      long long mana = min(1LL * t[first] * p[i].r + p[i].s, 1LL * p[i].m);
      d[first].sum += mana;
      if (times.size() >= 2 && p[i].r > 0) {
        int critical = (p[i].m + p[i].r - 1) / p[i].r;
        int l, r;
        split(root, critical, l, r);
        if (r > 0) {
          d[r].add_b += p[i].m;
        }
        if (l > 0) {
          d[l].add_a += p[i].r;
        }
        root = merge(l, r);
      }
    }
    for (int j = 0; j < int((del[i]).size()); ++j) {
      del_query(del[i][j]);
    }
  }
  for (int i = 1; i <= m; ++i) {
    printf(
        "%lld"
        "\n",
        d[i].sum);
  }
  return 0;
}
