#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T x, T y) {
  if (x < y) swap(x, y);
  while (y > 0) {
    T f = x % y;
    x = y;
    y = f;
  }
  return x;
}
struct Node {
  Node *l, *r;
  long long a, b;
  Node() : l(NULL), r(NULL), a(0), b(0) {}
};
Node* makeTree(int fr, int to) {
  Node* node = new Node();
  if (fr == to) return node;
  int m = (fr + to) / 2;
  node->l = makeTree(fr, m);
  node->r = makeTree(m + 1, to);
  return node;
}
Node* update(Node* _node, int fr, int to, int x1, int x2, long long a,
             long long b) {
  if (x2 < fr || x1 > to) return _node;
  Node* node = new Node();
  *node = *_node;
  if (x1 <= fr && to <= x2) {
    node->a += a;
    node->b += b;
    return node;
  }
  int m = (fr + to) / 2;
  node->l = update(node->l, fr, m, x1, x2, a, b);
  node->r = update(node->r, m + 1, to, x1, x2, a, b);
  return node;
}
long long query(Node* node, int fr, int to, long long x) {
  long long res = node->a * x + node->b;
  if (fr == to) return res;
  int m = (fr + to) / 2;
  if (x <= m)
    return res + query(node->l, fr, m, x);
  else
    return res + query(node->r, m + 1, to, x);
}
Node* froot[75007];
const int maxx = 200002;
int main(int argc, char* argv[]) {
  int n;
  std::cin.sync_with_stdio(false);
  std::cin.tie(nullptr);
  cin >> n;
  {
    froot[0] = makeTree(0, maxx);
    for (int i = 1; i <= n; i++) {
      int x1, x2, y1, a, b, y2;
      cin >> x1 >> x2 >> y1 >> a >> b >> y2;
      froot[i] = update(froot[i - 1], 0, maxx, 0, x1, 0, y1);
      froot[i] = update(froot[i], 0, maxx, x1 + 1, x2, a, b);
      froot[i] = update(froot[i], 0, maxx, x2 + 1, maxx, 0, y2);
    }
    int m;
    cin >> m;
    long long last = 0;
    while (m--) {
      int l, r, x;
      cin >> l >> r >> x;
      last = (last + x) % 1000000000ll;
      last =
          query(froot[r], 0, maxx, last) - query(froot[l - 1], 0, maxx, last);
      cout << last << endl;
    }
  }
  return 0;
}
