#include <bits/stdc++.h>
using namespace std;
const int maxN = 3e5 + 10;
struct Segment {
  int l, r;
  pair<long long, long long> num;
} tree[maxN * 30 + 1];
struct Node {
  int x, op, a, b;
  Node(int X = 0, int Y = 0, int Z = 0, int W = 0) {
    x = X;
    op = Y;
    a = Z;
    b = W;
  }
} a[maxN + 1];
int n, m, cnt;
int tmp[maxN + 1], res, root[maxN + 1];
inline int read() {
  int num = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) num = (num << 3) + (num << 1) + (ch ^ 48), ch = getchar();
  return num * f;
}
inline bool comp(Node a, Node b) { return a.x < b.x; }
inline pair<long long, long long> ADD(pair<long long, long long> a,
                                      pair<long long, long long> b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
inline void pushup(int node) {
  tree[node].num = ADD(tree[tree[node].l].num, tree[tree[node].r].num);
}
inline int build(int l, int r) {
  int node = ++cnt;
  if (l == r) {
    tree[node].num = make_pair(0, 0);
    return node;
  }
  int mid = (l + r) >> 1;
  tree[node].l = build(l, mid);
  tree[node].r = build(mid + 1, r);
  pushup(node);
  return node;
}
inline int change(int pre, int l, int r, int x,
                  pair<long long, long long> num) {
  int node = ++cnt;
  if (l == r) {
    tree[node].num = num;
    return node;
  }
  int mid = (l + r) >> 1;
  tree[node].l = tree[pre].l;
  tree[node].r = tree[pre].r;
  if (x <= mid)
    tree[node].l = change(tree[pre].l, l, mid, x, num);
  else
    tree[node].r = change(tree[pre].r, mid + 1, r, x, num);
  pushup(node);
  return node;
}
inline pair<long long, long long> query(int node, int l, int r, int x, int y) {
  if (!node) return make_pair(0, 0);
  if (x <= l && r <= y) return tree[node].num;
  int mid = (l + r) >> 1;
  pair<long long, long long> ans = make_pair(0, 0);
  if (x <= mid) ans = ADD(ans, query(tree[node].l, l, mid, x, y));
  if (y > mid) ans = ADD(ans, query(tree[node].r, mid + 1, r, x, y));
  return ans;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    int l = read() + 1, r = read() + 1, ya = read(), ta = read(), tb = read(),
        yb = read();
    a[++res] = Node(0, i, 0, ya);
    a[++res] = Node(l, i, ta, tb);
    a[++res] = Node(r, i, 0, yb);
  }
  sort(a + 1, a + res + 1, comp);
  root[0] = build(1, n);
  for (int i = 1; i <= res; i++) {
    tmp[i] = a[i].x;
    root[i] = change(root[i - 1], 1, n, a[i].op, make_pair(a[i].a, a[i].b));
  }
  long long last = 0, mod = 1e9;
  m = read();
  while (m--) {
    int l = read(), r = read(), x = (read() + last) % mod;
    int t = upper_bound(tmp + 1, tmp + res + 1, x) - tmp - 1;
    pair<long long, long long> ans = query(root[t], 1, n, l, r);
    printf("%lld\n", last = 1ll * ans.first * x + ans.second);
  }
  return 0;
}
