#include <bits/stdc++.h>
using namespace std;
const int N = 1e9;
const int sup = 210000;
const int max_n = 75555;
struct node {
  node *l, *r;
  long long a, b;
  node() {
    a = b = 0;
    l = r = NULL;
  }
};
node *build(int tl, int tr) {
  node *v = new node();
  if (tl == tr) return v;
  int m = (tl + tr) >> 1;
  v->l = build(tl, m);
  v->r = build(m + 1, tr);
  return v;
}
node *update(node *v, int tl, int tr, int l, int r, long long a, long long b) {
  if (tl > r || tr < l) return v;
  node *u = new node();
  *u = *v;
  if (l <= tl && tr <= r) {
    u->a += a;
    u->b += b;
    return u;
  }
  int m = (tl + tr) >> 1;
  u->l = update(u->l, tl, m, l, r, a, b);
  u->r = update(u->r, m + 1, tr, l, r, a, b);
  return u;
}
long long get(node *v, int tl, int tr, long long x) {
  long long ans = x * (v->a) + (v->b);
  if (tl == tr) return ans;
  int m = (tl + tr) >> 1;
  if (x <= m) return get(v->l, tl, m, x) + ans;
  return get(v->r, m + 1, tr, x) + ans;
}
node *cur[max_n];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  node *root = build(0, sup);
  cur[0] = root;
  for (int i = 1; i <= n; i++) {
    long long x1, x2, y1, y2, a, b;
    cin >> x1 >> x2 >> y1 >> a >> b >> y2;
    root = update(root, 0, sup, 0, x1, 0, y1);
    root = update(root, 0, sup, x1 + 1, x2, a, b);
    root = update(root, 0, sup, x2 + 1, sup, 0, y2);
    cur[i] = root;
  }
  int q;
  cin >> q;
  long long ans = 0, x, l, r;
  while (q--) {
    cin >> l >> r >> x;
    x = (x + ans) % N;
    if (x >= sup) x = sup - 10;
    ans = get(cur[r], 0, sup, x) - get(cur[l - 1], 0, sup, x);
    cout << ans << '\n';
  }
  return 0;
}
