#include <bits/stdc++.h>
struct element {
  int x;
  long long y;
  element(int x_ = 0, long long y_ = 0) {
    x = x_;
    y = y_;
  }
  element operator+(element arg) { return element(x + arg.x, y + arg.y); }
  element operator-(element arg) { return element(x - arg.x, y - arg.y); }
  long long operator()(int p) { return (long long)p * x + y; }
};
class node {
  element v;
  int tl, tr;

 public:
  node *left, *right;
  node() { left = right = 0; }
  void resize(int n) {
    tl = 0;
    tr = n;
  }
  node *update(int l, int r, element x);
  element query(int i);
};
node *node::update(int l, int r, element x) {
  if (!(tl >= r || tr <= l)) {
    node *cur = new node;
    *cur = *this;
    if (tl >= l && tr <= r)
      cur->v = v + x;
    else {
      int m = (tl + tr) >> 1;
      if (!left) {
        cur->left = new node;
        cur->left->tl = tl;
        cur->left->tr = m;
      }
      cur->left = cur->left->update(l, r, x);
      if (!right) {
        cur->right = new node;
        cur->right->tl = m;
        cur->right->tr = tr;
      }
      cur->right = cur->right->update(l, r, x);
    }
    return cur;
  }
  return this;
}
element node::query(int i) {
  if (i < tl + tr >> 1) return v + (left ? left->query(i) : element());
  return v + (right ? right->query(i) : element());
}
const int N = 75000;
const int V = 1000000000;
int n, m;
node *rt[N + 1];
int main() {
  scanf("%d", &n);
  rt[0] = new node;
  rt[0]->resize(V);
  for (int i = 1; i <= n; ++i) {
    int x1, x2, y1, a, b, y2;
    scanf("%d%d%d%d%d%d", &x1, &x2, &y1, &a, &b, &y2);
    rt[i] = new node();
    rt[i] = rt[i - 1]->update(0, x1 + 1, element(0, y1));
    rt[i] = rt[i]->update(x1 + 1, x2 + 1, element(a, b));
    rt[i] = rt[i]->update(x2 + 1, V, element(0, y2));
  }
  long long last = 0;
  scanf("%d", &m);
  while (m--) {
    int l, r, x;
    scanf("%d%d%d", &l, &r, &x);
    last = (last + x) % V;
    last = (rt[r]->query(last) - rt[l - 1]->query(last))(last);
    printf("%lld\n", last);
  }
  return 0;
}
