#include <bits/stdc++.h>
using namespace std;
struct node {
  long long sum, sum_idx;
  node *left, *right;
  node() {
    sum = sum_idx = 0;
    left = right = this;
  }
  node(long long s, long long s_idx, node *l = new node, node *r = new node) {
    sum = s, sum_idx = s_idx;
    left = l, right = r;
  }
};
node *insert(node *root, int l, int r, long long val, int lx = 0,
             int rx = 1000000010) {
  if (lx > r || rx < l) return root;
  if (lx >= l && rx <= r)
    return new node(root->sum + val, root->sum_idx, root->left, root->right);
  int mid = (lx + rx) / 2;
  node *ln = insert(root->left, l, r, val, lx, mid);
  node *rn = insert(root->right, l, r, val, mid + 1, rx);
  return new node(root->sum, root->sum_idx, ln, rn);
}
node *insert_idx(node *root, int l, int r, long long val, int lx = 0,
                 int rx = 1000000010) {
  if (lx > r || rx < l) return root;
  if (lx >= l && rx <= r)
    return new node(root->sum, root->sum_idx + val, root->left, root->right);
  int mid = (lx + rx) / 2;
  node *ln = insert_idx(root->left, l, r, val, lx, mid);
  node *rn = insert_idx(root->right, l, r, val, mid + 1, rx);
  return new node(root->sum, root->sum_idx, ln, rn);
}
long long query(node *l_root, node *r_root, int i, long long s = 0, int lx = 0,
                int rx = 1000000010) {
  if (lx == rx)
    return (s + (r_root->sum - l_root->sum)) +
           (r_root->sum_idx - l_root->sum_idx) * i;
  int mid = (lx + rx) / 2;
  s += (r_root->sum - l_root->sum) + (r_root->sum_idx - l_root->sum_idx) * i;
  if (i <= mid) return query(l_root->left, r_root->left, i, s, lx, mid);
  return query(l_root->right, r_root->right, i, s, mid + 1, rx);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m, x1, x2, y1, y2, a, b, l, r, x, last = 0;
  cin >> n;
  vector<node *> roots(n + 1);
  roots[0] = new node;
  for (int i = 1; i <= n; i++) {
    cin >> x1 >> x2 >> y1 >> a >> b >> y2;
    roots[i] = insert(roots[i - 1], 0, x1, y1);
    roots[i] = insert(roots[i], x1 + 1, x2, b);
    roots[i] = insert_idx(roots[i], x1 + 1, x2, a);
    roots[i] = insert(roots[i], x2 + 1, 1000000010, y2);
  }
  cin >> m;
  while (m--) {
    cin >> l >> r >> x;
    x = (x + last) % 1000000000;
    last = query(roots[l - 1], roots[r], x);
    cout << last << "\n";
  }
  return 0;
}
