#include <bits/stdc++.h>
using namespace std;
int n, m, idx = -1;
long long last;
const int mod = 1e9;
struct node {
  int lc = 0, rc = 0;
  pair<long long, long long> val = {0, 0};
};
vector<node> pt;
void update(int v, int l, int r, int L, int R, pair<long long, long long> val) {
  if (R < L) return;
  if (l == L && r == R) {
    pt[v].val.first += val.first;
    pt[v].val.second += val.second;
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) {
    int x = pt[v].lc;
    pt[v].lc = ++idx;
    pt.push_back(pt[x]);
    update(pt[v].lc, l, mid, L, min(R, mid), val);
  }
  if (R > mid) {
    int x = pt[v].rc;
    pt[v].rc = ++idx;
    pt.push_back(pt[x]);
    update(pt[v].rc, mid + 1, r, max(L, mid + 1), R, val);
  }
}
long long get(int v, int l, int r, long long pos) {
  if (!v) return 0;
  int mid = (l + r) >> 1;
  if (pos <= mid) {
    return pt[v].val.first * pos + pt[v].val.second +
           get(pt[v].lc, l, mid, pos);
  }
  return get(pt[v].rc, mid + 1, r, pos) + pt[v].val.first * pos +
         pt[v].val.second;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  int root[n + 1];
  node x;
  x.lc = 0;
  x.rc = 0;
  x.val = {0, 0};
  root[0] = ++idx;
  pt.push_back(x);
  for (int i = 0; i < n; ++i) {
    int x1, x2, y2, a, b, y1;
    cin >> x1 >> x2 >> y1 >> a >> b >> y2;
    root[i + 1] = ++idx;
    pt.push_back(pt[root[i]]);
    pt[root[i + 1]] = pt[root[i]];
    update(root[i + 1], 0, mod, 0, x1, {0, y1});
    update(root[i + 1], 0, mod, x1 + 1, x2, {a, b});
    update(root[i + 1], 0, mod, x2 + 1, mod, {0, y2});
  }
  cin >> m;
  while (m--) {
    int l, r, x;
    cin >> l >> r >> x;
    x = (x + last) % mod;
    long long ans = get(root[r], 0, mod, x) - get(root[l - 1], 0, mod, x);
    cout << ans << '\n';
    last = ans;
  }
  return 0;
}
