#include <bits/stdc++.h>
using namespace std;
const double eps = 0.000000000000001;
int n, m;
long long x1[75010], x2[75010], Y1[75010], A[75010], B[75010], y2[75010];
struct stik {
  vector<pair<int, long long> > bakcmy1, cmy2;
  vector<pair<int, long long> > acmx1, acmx2;
  vector<pair<int, long long> > bcmx1, bcmx2;
};
stik nod[4 * 75010];
inline void mergem(stik &pre, stik &p, stik &q) {
  merge(p.bakcmy1.begin(), p.bakcmy1.end(), q.bakcmy1.begin(), q.bakcmy1.end(),
        pre.bakcmy1.begin());
  merge(p.cmy2.begin(), p.cmy2.end(), q.cmy2.begin(), q.cmy2.end(),
        pre.cmy2.begin());
  merge(p.acmx1.begin(), p.acmx1.end(), q.acmx1.begin(), q.acmx1.end(),
        pre.acmx1.begin());
  merge(p.acmx2.begin(), p.acmx2.end(), q.acmx2.begin(), q.acmx2.end(),
        pre.acmx2.begin());
  merge(p.bcmx1.begin(), p.bcmx1.end(), q.bcmx1.begin(), q.bcmx1.end(),
        pre.bcmx1.begin());
  merge(p.bcmx2.begin(), p.bcmx2.end(), q.bcmx2.begin(), q.bcmx2.end(),
        pre.bcmx2.begin());
}
void precal(int no, int a, int b) {
  if (a > b) {
    assert(false);
    return;
  }
  if (a == b) {
    nod[no].bakcmy1.push_back(make_pair(x1[a], Y1[a]));
    nod[no].cmy2.push_back(make_pair(x2[a], y2[a]));
    nod[no].acmx1.push_back(make_pair(x1[a], A[a]));
    nod[no].acmx2.push_back(make_pair(x2[a], A[a]));
    nod[no].bcmx1.push_back(make_pair(x1[a], B[a]));
    nod[no].bcmx2.push_back(make_pair(x2[a], B[a]));
    return;
  }
  int mid = (a + b) >> 1, lc = (no << 1), rc = lc + 1;
  precal(lc, a, mid);
  precal(rc, mid + 1, b);
  nod[no].bakcmy1.resize(b - a + 1);
  nod[no].cmy2.resize(b - a + 1);
  nod[no].acmx1.resize(b - a + 1);
  nod[no].acmx2.resize(b - a + 1);
  nod[no].bcmx1.resize(b - a + 1);
  nod[no].bcmx2.resize(b - a + 1);
  mergem(nod[no], nod[lc], nod[rc]);
}
inline void cumuit(vector<pair<int, long long> > &x) {
  int i, j;
  for (i = 1; i < x.size(); i++) {
    x[i].second = x[i - 1].second + x[i].second;
  }
}
void precal2(int no, int a, int b) {
  if (a == b) {
    return;
  }
  int i;
  int mid = (a + b) >> 1, lc = (no << 1), rc = lc + 1;
  precal2(lc, a, mid);
  precal2(rc, mid + 1, b);
  cumuit(nod[no].cmy2);
  cumuit(nod[no].acmx1);
  cumuit(nod[no].acmx2);
  cumuit(nod[no].bcmx1);
  cumuit(nod[no].bcmx2);
  for (i = nod[no].bakcmy1.size() - 2; i >= 0; i--) {
    nod[no].bakcmy1[i].second += nod[no].bakcmy1[i + 1].second;
  }
}
pair<long long, long long> query(int no, int a, int b, int l, int r, int x) {
  if (a > b || b < l || a > r) {
    return make_pair(0, 0);
  }
  if (l <= a && b <= r) {
    long long sma = 0, smb = 0;
    long long othercons = 0;
    int ind;
    ind = lower_bound(nod[no].acmx1.begin(), nod[no].acmx1.end(),
                      make_pair(x, 0LL)) -
          nod[no].acmx1.begin();
    assert(nod[no].bakcmy1.size() == b - a + 1 &&
           nod[no].acmx1.size() == b - a + 1);
    if (ind < nod[no].bakcmy1.size()) {
      othercons += nod[no].bakcmy1[ind].second;
    }
    if (ind > 0) {
      ind--;
      sma += nod[no].acmx1[ind].second;
      smb += nod[no].bcmx1[ind].second;
    }
    ind = lower_bound(nod[no].acmx2.begin(), nod[no].acmx2.end(),
                      make_pair(x, 0LL)) -
          nod[no].acmx2.begin();
    if (ind > 0) {
      ind--;
      othercons += nod[no].cmy2[ind].second;
      sma -= nod[no].acmx2[ind].second;
      smb -= nod[no].bcmx2[ind].second;
    }
    return make_pair(sma, smb + othercons);
  }
  int mid = (a + b) >> 1, lc = (no << 1), rc = lc + 1;
  pair<long long, long long> alpha = query(lc, a, mid, l, r, x);
  pair<long long, long long> beta = query(rc, mid + 1, b, l, r, x);
  pair<long long, long long> ret =
      make_pair(alpha.first + beta.first, alpha.second + beta.second);
  return ret;
}
int main() {
  scanf("%d", &n);
  int i, j;
  for (i = 1; i <= n; i++) {
    scanf("%lld%lld%lld", &x1[i], &x2[i], &Y1[i]);
    scanf("%lld%lld%lld", &A[i], &B[i], &y2[i]);
    assert(x1[i] < x2[i]);
  }
  precal(1, 1, n);
  precal2(1, 1, n);
  scanf("%d", &m);
  long long ans = 0;
  for (i = 0; i < m; i++) {
    int l, r, x;
    scanf("%d%d%d", &l, &r, &x);
    x = (x + (ans % 1000000000)) % (1000000000);
    pair<long long, long long> got = query(1, 1, n, l, r, x);
    ans = got.first * x + got.second;
    printf("%lld\n", ans);
  }
  return 0;
}
