#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
bool Max(T1& a, T2 b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T1, typename T2>
bool Min(T1& a, T2 b) {
  return a > b ? a = b, 1 : 0;
}
const int N = 200000, M = 75000;
struct node {
  node *l = 0, *r = 0;
  long long a = 0, b = 0;
} nodes[1];
node* newnode = nodes;
node* ver[M + 1];
node* add(node* p, int l, int r, int x, int a, int b) {
  node* cur = new node;
  if (p) *cur = *p;
  cur->a += a;
  cur->b += b;
  if (l == r) {
    return cur;
  }
  int m = l + r >> 1;
  if (x <= m)
    cur->l = add(cur->l, l, m, x, a, b);
  else
    cur->r = add(cur->r, m + 1, r, x, a, b);
  return cur;
}
long long get(node* p, int l, int r, int x) {
  if (!p) return 0;
  if (x >= r) return p->a * x + p->b;
  int m = l + r >> 1;
  long long ret = get(p->l, l, m, x);
  if (x > m) ret += get(p->r, m + 1, r, x);
  return ret;
}
void solve() {
  int n, m;
  cin >> n;
  for (int i = 1; i <= (n); ++i) {
    int x1, x2, y1, a, b, y2;
    cin >> x1 >> x2 >> y1 >> a >> b >> y2;
    ver[i] = ver[i - 1];
    ver[i] = add(ver[i], 0, N, 0, 0, y1);
    ver[i] = add(ver[i], 0, N, x1 + 1, a, b - y1);
    ver[i] = add(ver[i], 0, N, x2 + 1, -a, y2 - b);
  }
  cin >> m;
  long long last = 0;
  while (m--) {
    int l, r, x;
    cin >> l >> r >> x;
    x = (x + last) % 1000000000;
    last = get(ver[r], 0, N, x) - get(ver[l - 1], 0, N, x);
    cout << last << '\n';
  }
}
void init() {}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.setf(ios::fixed);
  cout.precision(20);
  init();
  int TC = 1;
  for (int TI = 1; TI <= (TC); ++TI) {
    solve();
  }
  return 0;
}
