#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
#pragma GCC target("avx2")
using namespace std;
template <class T>
void read(T &num) {
  num = 0;
  char c = ' ';
  int flag = 1;
  for (; c > '9' || c < '0'; c = getchar())
    if (c == '-') flag = -1;
  for (; c >= '0' && c <= '9';
       num = (num << 1) + (num << 3) + c - 48, c = getchar())
    ;
  num = num * flag;
}
const int MOD = 1e9;
const long long INF = 1LL << 62;
const double PI = acos(-1);
const int maxn = 2e5;
struct node {
  int l_id, r_id;
  long long val;
  node *l_child, *r_child;
  node() {}
  node(int L_id, int R_id, long long S, node *L_Child, node *R_Child) {
    l_id = L_id, r_id = R_id, val = S, l_child = L_Child, r_child = R_Child;
  }
};
int n, m, sz[3];
node *version[3][maxn * 5];
void Enter() {}
void Build(node *n) {
  int l = n->l_id, r = n->r_id;
  if (l == r) {
    n->val = 0LL;
    return;
  }
  int m = (l + r) >> 1;
  n->l_child = new node(l, m, 0LL, nullptr, nullptr);
  n->r_child = new node(m + 1, r, 0LL, nullptr, nullptr);
  Build(n->l_child);
  Build(n->r_child);
  n->val = 0LL;
}
void Update(node *pre, node *cur, int idx, int delta) {
  int l = cur->l_id, r = cur->r_id;
  if (idx < l || r < idx) return;
  if (l == r) {
    cur->val = pre->val + delta;
    return;
  }
  int m = (l + r) >> 1;
  if (idx <= m) {
    cur->r_child = pre->r_child;
    cur->l_child = new node(l, m, 0LL, nullptr, nullptr);
    Update(pre->l_child, cur->l_child, idx, delta);
  } else {
    cur->l_child = pre->l_child;
    cur->r_child = new node(m + 1, r, 0LL, nullptr, nullptr);
    Update(pre->r_child, cur->r_child, idx, delta);
  }
  cur->val = cur->l_child->val + cur->r_child->val;
}
long long Query(node *left, node *right, int u, int v) {
  long long ans = 0;
  int l = left->l_id, r = left->r_id;
  if (r < u || v < l) return 0;
  if (u <= l && r <= v) return right->val - left->val;
  return Query(left->l_child, right->l_child, u, v) +
         Query(left->r_child, right->r_child, u, v);
}
void Solve() {
  node *root = new node(0, maxn + 1, 0LL, nullptr, nullptr);
  Build(root);
  version[0][0] = root;
  version[1][0] = root;
  version[2][0] = root;
  read(n);
  long long x1, x2, y1, a, b, y2;
  for (int i = 1; i <= n; i++) {
    read(x1);
    read(x2);
    read(y1);
    read(a);
    read(b);
    read(y2);
    version[0][++sz[0]] = new node(0, maxn + 1, 0LL, nullptr, nullptr);
    Update(version[0][sz[0] - 1], version[0][sz[0]], 0, y1);
    version[0][++sz[0]] = new node(0, maxn + 1, 0LL, nullptr, nullptr);
    Update(version[0][sz[0] - 1], version[0][sz[0]], x1 + 1, -y1);
    version[0][++sz[0]] = new node(0, maxn + 1, 0LL, nullptr, nullptr);
    Update(version[0][sz[0] - 1], version[0][sz[0]], x2 + 1, y2);
    version[1][++sz[1]] = new node(0, maxn + 1, 0LL, nullptr, nullptr);
    Update(version[1][sz[1] - 1], version[1][sz[1]], x1 + 1, a);
    version[1][++sz[1]] = new node(0, maxn + 1, 0LL, nullptr, nullptr);
    Update(version[1][sz[1] - 1], version[1][sz[1]], x2 + 1, -a);
    version[2][++sz[2]] = new node(0, maxn + 1, 0LL, nullptr, nullptr);
    Update(version[2][sz[2] - 1], version[2][sz[2]], x1 + 1, b);
    version[2][++sz[2]] = new node(0, maxn + 1, 0LL, nullptr, nullptr);
    Update(version[2][sz[2] - 1], version[2][sz[2]], x2 + 1, -b);
  }
  read(m);
  long long ans = 0;
  for (int i = 1, l, r, x; i <= m; i++) {
    read(l);
    read(r);
    read(x);
    x = (0LL + x + ans) % MOD;
    x = (x >= maxn + 1 ? maxn + 1 : x);
    ans = Query(version[0][(l - 1) * 3], version[0][r * 3], 0, x);
    ans += Query(version[1][(l - 1) * 2], version[1][r * 2], 0, x) * x +
           Query(version[2][(l - 1) * 2], version[2][r * 2], 0, x);
    printf("%lld\n", ans);
  }
}
int main() {
  Enter();
  Solve();
}
