#include <bits/stdc++.h>
template <typename T>
struct SegmentTree {
 private:
  using F = std::function<T(T, T)>;
  int n;
  F f;
  T ti;
  std::vector<T> dat;

 public:
  SegmentTree(){};
  SegmentTree(F f, T ti) : f(f), ti(ti) {}
  void build(int n_) {
    n = n_;
    dat.assign(2 * n, ti);
  }
  void build(const std::vector<T> &v) {
    int n_ = v.size();
    build(n_);
    for (int i = 0; i < n; ++i) dat[n + i] = v[i];
    for (int i = n - 1; i >= 0; --i) dat[i] = f(dat[2 * i + 0], dat[2 * i + 1]);
  }
  long long query(int a, int b, int x) {
    if (a == b) return 0;
    long long ret = 0;
    for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) ret += dat[l++].query(x);
      if (r & 1) ret += dat[--r].query(x);
    }
    return ret;
  }
};
using namespace std;
using ll = long long;
using arr = array<ll, 3>;
const ll INF = 1e9;
struct F {
  vector<arr> C;
  F(ll x1, ll x2, ll y1, ll a, ll b, ll y2)
      : C({{x1, 0, y1}, {x2, a, b}, {INF, 0, y2}}) {}
  F(vector<arr> C) : C(C) {}
  ll query(ll x) {
    auto c = *lower_bound(C.begin(), C.end(), arr{x, -INF, -INF});
    return x * c[1] + c[2];
  }
};
int main() {
  function<F(F, F)> f = [&](F a, F b) {
    set<ll> X;
    for (auto e : a.C) X.insert(e[0]);
    for (auto e : b.C) X.insert(e[0]);
    vector<arr> C;
    for (auto e : X) {
      auto aa = *lower_bound(a.C.begin(), a.C.end(), arr{e, -INF, -INF});
      auto bb = *lower_bound(b.C.begin(), b.C.end(), arr{e, -INF, -INF});
      C.push_back({e, aa[1] + bb[1], aa[2] + bb[2]});
    }
    return F(C);
  };
  F ti({{INF, 0, 0}});
  int n;
  scanf("%d", &n);
  vector<F> ini;
  for (int i = 0; i < n; ++i) {
    ll x1, x2, y1, a, b, y2;
    scanf("%lld %lld %lld %lld %lld %lld", &x1, &x2, &y1, &a, &b, &y2);
    ini.emplace_back(x1, x2, y1, a, b, y2);
  }
  SegmentTree<F> st(f, ti);
  st.build(ini);
  int q;
  scanf("%d", &q);
  ll last = 0, mod = 1e9;
  while (q--) {
    int l, r, x;
    scanf("%d %d %d", &l, &r, &x);
    --l;
    x = (x + last) % mod;
    last = st.query(l, r, x);
    printf("%lld\n", last);
    ll ret = 0;
  }
}
