#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T a, T b) {
  ;
}
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
namespace std {
template <class S, class T>
ostream& operator<<(ostream& out, const pair<S, T>& a) {
  out << '(' << a.first << ',' << a.second << ')';
  return out;
}
}  // namespace std
const int INF1 = 1e9 + 5;
const long long int INF2 = 1e18;
int n, m;
long long int st[100005], mx[100005], incr[100005];
struct segtree {
  int start[400005];
  vector<pair<pair<long long int, long long int>, long long int> > val[270000];
  int n;
  pair<pair<long long int, long long int>, long long int> make(int m,
                                                               int incr) {
    pair<pair<long long int, long long int>, long long int> res;
    if (incr == 0)
      res.first.first = INF1;
    else
      res.first.first = m / incr;
    res.first.second = m;
    res.second = incr;
    return res;
  }
  void mrg(int i) {
    if (start[i * 2 + 1] == start[i * 2 + 2])
      start[i] = start[i * 2 + 1];
    else if (start[i * 2 + 2] == -2)
      start[i] = start[i * 2 + 1];
    else
      start[i] = -1;
  }
  void push(int i) {
    if (start[i] >= 0) {
      start[i * 2 + 1] = start[i];
      start[i * 2 + 2] = start[i];
    }
  }
  void init(int n_) {
    n = 1;
    while (n < n_) n <<= 1;
    for (int i = 0; i < (n); ++i) start[i + n - 1] = -2;
    for (int i = 0; i < (n_); ++i) {
      start[i + n - 1] = 0;
      val[i + n - 1].push_back(make(mx[i], incr[i]));
    }
    for (int i = n - 2; i >= 0; --i) {
      mrg(i);
      val[i].resize(val[i * 2 + 1].size() + val[i * 2 + 2].size());
      merge((val[i * 2 + 1]).begin(), (val[i * 2 + 1]).end(),
            (val[i * 2 + 2]).begin(), (val[i * 2 + 2]).end(), val[i].begin());
    }
    for (int i = n - 2; i >= 0; --i)
      if (!val[i].empty()) {
        for (int j = 0; j < (val[i].size() - 1); ++j) {
          val[i][j + 1].first.second += val[i][j].first.second;
          val[i][j + 1].second += val[i][j].second;
        }
      }
  }
  long long int query(int a, int b, int i, int l, int r, int t) {
    if (a <= l && r <= b && (start[i] > 0 || r - l == 1)) {
      int dif = t - start[i];
      if (start[i] == 0) {
        start[i] = t;
        return min(mx[l], st[l] + incr[l] * t);
      }
      int lb =
          lower_bound((val[i]).begin(), (val[i]).end(),
                      (pair<pair<long long int, long long int>, long long int>)
                          make_pair(make_pair(dif, -1), -1)) -
          val[i].begin();
      long long int res = 0;
      if (lb > 0) {
        --lb;
        res += val[i][lb].first.second;
        res += (val[i].back().second - val[i][lb].second) * dif;
      } else {
        res += val[i].back().second * dif;
      }
      start[i] = t;
      return res;
    }
    if (b <= l || r <= a) return 0;
    int md = (l + r) >> 1;
    push(i);
    long long int lch = query(a, b, i * 2 + 1, l, md, t),
                  rch = query(a, b, i * 2 + 2, md, r, t);
    mrg(i);
    return lch + rch;
  }
};
segtree seg;
int main() {
  cin >> n;
  for (int i = 0; i < (n); ++i) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    st[i] = a;
    mx[i] = b;
    incr[i] = c;
  }
  seg.init(n);
  cin >> m;
  for (int hoge = 0; hoge < (m); ++hoge) {
    int t, l, r;
    scanf("%d%d%d", &t, &l, &r);
    --l;
    long long int res = seg.query(l, r, 0, 0, seg.n, t);
    cout << res << '\n';
  }
  return 0;
}
