#include <bits/stdc++.h>
using namespace std;
using vint = vector<long long>;
using pint = pair<long long, long long>;
using vpint = vector<pint>;
template <typename A, typename B>
inline void chmin(A &a, B b) {
  if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b) {
  if (a < b) a = b;
}
template <class A, class B>
ostream &operator<<(ostream &ost, const pair<A, B> &p) {
  ost << "{" << p.first << "," << p.second << "}";
  return ost;
}
template <class T>
ostream &operator<<(ostream &ost, const vector<T> &v) {
  ost << "{";
  for (long long i = 0; i < v.size(); i++) {
    if (i) ost << ",";
    ost << v[i];
  }
  ost << "}";
  return ost;
}
inline long long topbit(unsigned long long x) {
  return x ? 63 - __builtin_clzll(x) : -1;
}
inline long long popcount(unsigned long long x) {
  return __builtin_popcountll(x);
}
inline long long parity(unsigned long long x) { return __builtin_parity(x); }
struct F {
  long long x1, x2, y1, y2, a, b;
};
struct UKU {
  vector<F> fs;
  vint ps;
  vint accA, accB;
  vint idxL, idxR;
  void add(F f) { fs.push_back(f); }
  inline long long idx(long long x) {
    return upper_bound((ps).begin(), (ps).end(), x) - ps.begin() - 1;
  }
  void build() {
    for (auto &f : fs) {
      ps.push_back(f.x1);
      ps.push_back(f.x2);
    }
    ps.push_back(0);
    ps.push_back(1000000000);
    sort((ps).begin(), (ps).end());
    ps.erase(unique((ps).begin(), (ps).end()), ps.end());
    accA.resize(ps.size());
    accB.resize(ps.size());
    for (auto &f : fs) {
      f.x1 = idx(f.x1);
      f.x2 = idx(f.x2);
      accB[0] += f.y1;
      accB[f.x1] -= f.y1;
      accA[f.x1] += f.a;
      accB[f.x1] += f.b;
      accA[f.x2] -= f.a;
      accB[f.x2] -= f.b;
      accB[f.x2] += f.y2;
    }
    for (long long i = 0; i + 1 < ps.size(); i++) {
      accA[i + 1] += accA[i];
      accB[i + 1] += accB[i];
    }
  }
  long long calc(long long x, long long realX) {
    long long a = accA[x];
    long long b = accB[x];
    return a * realX + b;
  }
};
inline void calcIndex(vint &p, vint &c, vint &idx) {
  long long cur = 0;
  idx.resize(p.size());
  for (long long i = 0; i < p.size(); i++) {
    while (cur + 1 < c.size() && c[cur + 1] <= p[i]) cur++;
    idx[i] = cur;
  }
}
struct segtree {
  static const long long SEG = 1 << 17;
  vector<UKU> dat;
  segtree() : dat(SEG * 2) {}
  void add(long long k, F f) {
    k += SEG - 1;
    while (true) {
      dat[k].add(f);
      if (k == 0) break;
      k = (k - 1) / 2;
    }
  }
  void build(long long k = 0, long long l = 0, long long r = SEG) {
    dat[k].build();
    if (l + 1 == r) return;
    build(k * 2 + 1, l, (l + r) / 2);
    build(k * 2 + 2, (l + r) / 2, r);
    calcIndex(dat[k].ps, dat[k * 2 + 1].ps, dat[k].idxL);
    calcIndex(dat[k].ps, dat[k * 2 + 2].ps, dat[k].idxR);
  }
  long long query(long long a, long long b, long long x, long long realX,
                  long long k = 0, long long l = 0, long long r = SEG) {
    if (r <= a || b <= l) return 0;
    if (a <= l && r <= b) {
      return dat[k].calc(x, realX);
    }
    return query(a, b, dat[k].idxL[x], realX, k * 2 + 1, l, (l + r) / 2) +
           query(a, b, dat[k].idxR[x], realX, k * 2 + 2, (l + r) / 2, r);
  }
};
long long N;
F fs[111111];
signed main() {
  scanf("%lld", &N);
  for (long long i = 0; i < (N); i++) {
    long long x1, x2, y1, y2, a, b;
    scanf("%lld%lld%lld%lld%lld%lld", &x1, &x2, &y1, &a, &b, &y2);
    x1++;
    x2++;
    fs[i] = {x1, x2, y1, y2, a, b};
  }
  segtree seg;
  for (long long i = 0; i < (N); i++) seg.add(i, fs[i]);
  seg.build();
  long long last = 0;
  long long Q;
  scanf("%lld", &Q);
  while (Q--) {
    long long l, r, x;
    scanf("%lld%lld%lld", &l, &r, &x);
    l--;
    x = (x + last) % 1000000000;
    long long realX = x;
    x = seg.dat[0].idx(x);
    last = seg.query(l, r, x, realX);
    printf("%lld\n", last);
  }
  return 0;
}
