#include <bits/stdc++.h>
using namespace std;
const int M = 80005, Mlog = 17, mod = 1e9, SM = 3 * Mlog * M;
int root[3 * M], Lch[SM], Rch[SM], b[3 * M], cnt, n, m;
long long seg[2][SM];
pair<pair<int, int>, pair<int, int> > arr[3 * M];
int upd(int id, int p, pair<int, int> val, int l = 0, int r = n) {
  int nod = ++cnt;
  if (r - l < 2) {
    seg[0][nod] = seg[0][id] + val.first;
    seg[1][nod] = seg[1][id] + val.second;
    return nod;
  }
  int mid = (l + r) / 2;
  if (p < mid)
    Rch[nod] = Rch[id], Lch[nod] = upd(Lch[id], p, val, l, mid);
  else
    Lch[nod] = Lch[id], Rch[nod] = upd(Rch[id], p, val, mid, r);
  for (int i = 0; i < 2; i++) seg[i][nod] = seg[i][Lch[nod]] + seg[i][Rch[nod]];
  return nod;
}
long long get(int id, int ql, int qr, long long x, int l = 0, int r = n) {
  if (r <= ql || qr <= l) return 0;
  ;
  if (ql <= l && r <= qr) return seg[0][id] * x + seg[1][id];
  int mid = (l + r) / 2;
  return get(Lch[id], ql, qr, x, l, mid) + get(Rch[id], ql, qr, x, mid, r);
}
int32_t main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x11, x22, y11, a, b, y22;
    scanf("%d%d%d%d%d%d", &x11, &x22, &y11, &a, &b, &y22);
    arr[m++] = make_pair(make_pair(0, i), make_pair(0, y11));
    arr[m++] = make_pair(make_pair(x11 + 1, i), make_pair(a, b - y11));
    arr[m++] = make_pair(make_pair(x22 + 1, i), make_pair(-a, y22 - b));
  }
  sort(arr, arr + m);
  for (int i = 0; i < m; i++)
    b[i] = arr[i].first.first,
    root[i + 1] = upd(root[i], arr[i].first.second, arr[i].second);
  long long ans = 0;
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    long long x;
    scanf("%d%d%lld", &l, &r, &x);
    l--;
    x = (ans + x) % mod;
    int p = upper_bound(b, b + m, x) - b;
    ans = get(root[p], l, r, x);
    printf("%lld\n", ans);
  }
  return 0;
}
