#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 7;
const int M = 9;
const int inf = 1e9 + 7;
const long long linf = 1e18 + 7;
const double pi = acos(-1);
const double eps = 1e-7;
const bool multipleTest = 0;
class PersistentSegmentTree {
 public:
  const static int MAXN = N;
  const static int MM = MAXN * 40;
  struct node {
    int sumA;
    long long sumB;
    int leftChild;
    int rightChild;
    int timeIndex;
    node() {
      timeIndex = 0;
      sumA = sumB = 0;
      rightChild = leftChild = -1;
    }
    void reset(int u, int v, int _left, int _right) {
      sumA = sumB = 0;
      leftChild = _left;
      rightChild = _right;
    }
    void reset(node& o) {
      leftChild = o.leftChild;
      rightChild = o.rightChild;
      sumA = o.sumA;
      sumB = o.sumB;
      timeIndex = o.timeIndex;
    }
  };
  node tree[MM];
  int root[MAXN * 2];
  int curTime;
  int tolTime;
  int cnt = 0;
  void resetTime(int u) { curTime = u; }
  void buildTree(node& root, int l, int r) {
    if (l == r) {
      root.reset(l, r, -1, -1);
      return;
    }
    int g = (l + r) >> 1;
    int leftChild = cnt++, rightChild = cnt++;
    buildTree(tree[leftChild], l, g);
    buildTree(tree[rightChild], g + 1, r);
    root.reset(l, r, leftChild, rightChild);
  }
  void init(int l, int r) {
    cnt = 1;
    curTime = tolTime = 0;
    buildTree(tree[0], l, r);
    root[tolTime++] = 0;
  }
  void pushDown(node& root, int len, int A, long long B) {
    root.sumA += A;
    root.sumB += B;
  }
  int update(node& root, int l, int r, int u, int v, int A, long long B) {
    if (l == u && r == v) {
      int now = cnt++;
      tree[now].reset(root);
      tree[now].timeIndex = tolTime;
      pushDown(tree[now], r - l + 1, A, B);
      return now;
    }
    int g = (l + r) >> 1;
    int leftChild = root.leftChild, rightChild = root.rightChild;
    if (u <= g)
      leftChild = update(tree[root.leftChild], l, g, u, min(g, v), A, B);
    if (g < v)
      rightChild =
          update(tree[root.rightChild], g + 1, r, max(u, g + 1), v, A, B);
    int now = cnt++;
    tree[now].reset(root);
    tree[now].leftChild = leftChild;
    tree[now].rightChild = rightChild;
    tree[now].timeIndex = tolTime;
    tree[now].sumA = tree[leftChild].sumA + tree[rightChild].sumA;
    tree[now].sumB = tree[leftChild].sumB + tree[rightChild].sumB;
    return now;
  }
  void update(int u, int v, int A, long long B) {
    assert(u <= v);
    root[tolTime] = update(tree[root[curTime]], 0, N - 6, u, u, A, B);
    curTime = tolTime++;
    if (v + 1 <= N - 6) {
      root[tolTime] =
          update(tree[root[curTime]], 0, N - 6, v + 1, v + 1, -A, -B);
      curTime = tolTime++;
    }
  }
  pair<int, long long> get(node& root, int l, int r, int u, int v) {
    if (u <= l && r <= v) return make_pair(root.sumA, root.sumB);
    if (u > r || v < l) return make_pair(0, 0);
    int g = (l + r) >> 1;
    auto lhs = get(tree[root.leftChild], l, g, u, v);
    auto rhs = get(tree[root.rightChild], g + 1, r, u, v);
    return make_pair(lhs.first + rhs.first, lhs.second + rhs.second);
  }
  long long get(int tt, int pos, long long x) {
    auto xx = get(tree[root[tt]], 0, N - 6, 0, pos);
    return 1ll * xx.first * x + xx.second;
  }
} segmentTree;
int n;
int root[N];
void solve() {
  segmentTree.init(0, N - 6);
  root[0] = segmentTree.curTime;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int u1, u2, v1, v2, a, b;
    scanf("%d%d%d%d%d%d", &u1, &u2, &v1, &a, &b, &v2);
    segmentTree.update(0, u1, 0, v1);
    segmentTree.update(u1 + 1, u2, a, b);
    segmentTree.update(u2 + 1, N - 6, 0, v2);
    root[i] = segmentTree.curTime;
  }
  long long last = 0;
  int m;
  cin >> m;
  for (int j = 1; j <= m; ++j) {
    int u, v, x;
    scanf("%d%d%d", &u, &v, &x);
    x = (x + last) % 1000000000;
    int pos = x;
    if (pos > N - 6) pos = N - 6;
    last =
        segmentTree.get(root[v], pos, x) - segmentTree.get(root[u - 1], pos, x);
    printf("%lld\n", last);
  }
}
int main() {
  int Test = 1;
  if (multipleTest) {
    cin >> Test;
  }
  for (int i = 0; i < Test; ++i) {
    solve();
  }
}
