#include <bits/stdc++.h>
using namespace std;
struct node {
  node *l = nullptr;
  node *r = nullptr;
  long long val = 0;
};
constexpr int N = 1 << 18;
long long sum(node *x) { return x ? x->val : 0LL; }
node *update(int k, long long v, node *x, int l = 0, int r = N) {
  x = x ? new node(*x) : new node();
  if (r - l == 1) {
    x->val = v;
    return x;
  }
  int m = l + r >> 1;
  if (k < m) {
    x->l = update(k, v, x->l, l, m);
  } else {
    x->r = update(k, v, x->r, m, r);
  }
  x->val = sum(x->l) + sum(x->r);
  return x;
}
long long query(int a, int b, node *x, int l = 0, int r = N) {
  if (!x) return 0;
  if (r <= a || b <= l) return 0;
  if (a <= l && r <= b) return sum(x);
  int m = (l + r) / 2;
  return query(a, b, x->l, l, m) + query(a, b, x->r, m, r);
}
int main() {
  int n;
  cin >> n;
  vector<int> x1(n), x2(n), y1(n), y2(n), a(n), b(n);
  vector<node *> A(200010), B(200010);
  vector<vector<int>> add(200010);
  vector<vector<int>> del(200010);
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d%d%d%d", &x1[i], &x2[i], &y1[i], &a[i], &b[i], &y2[i]);
    B[0] = update(i, y1[i], B[0]);
    del[x1[i] + 1].push_back(i);
    add[x2[i] + 1].push_back(i);
  }
  for (int i = 1; i <= 200005; i++) {
    A[i] = A[i - 1];
    B[i] = B[i - 1];
    for (int id : del[i]) {
      A[i] = update(id, a[id], A[i]);
      B[i] = update(id, b[id], B[i]);
    }
    for (int id : add[i]) {
      A[i] = update(id, 0, A[i]);
      B[i] = update(id, y2[id], B[i]);
    }
  }
  int q;
  cin >> q;
  long long last = 0;
  constexpr long long mod = 1e9;
  while (q--) {
    int l, r, x;
    scanf("%d%d%d", &l, &r, &x);
    long long xi = (x + last) % mod;
    long long t = min(xi, 200002LL);
    l--;
    long long aa = query(l, r, A[t]);
    long long bb = query(l, r, B[t]);
    last = aa * xi + bb;
    printf("%lld\n", last);
  }
}
