#include <bits/stdc++.h>
using namespace std;
long long taga[10000100], tagb[10000100];
int lch[10000100], rch[10000100];
int tot, n, T, root[75010];
long long ans, A, B;
int modify(int pre, int l, int r, int L, int R, long long a, long long b) {
  int now = ++tot;
  if (L <= l && r <= R) {
    taga[now] = taga[pre] + a;
    tagb[now] = tagb[pre] + b;
    lch[now] = lch[pre], rch[now] = rch[pre];
  } else {
    int mid = (l + r) >> 1;
    if (L <= mid)
      lch[now] = modify(lch[pre], l, mid, L, R, a, b);
    else
      lch[now] = lch[pre];
    if (mid < R)
      rch[now] = modify(rch[pre], mid + 1, r, L, R, a, b);
    else
      rch[now] = rch[pre];
    taga[now] = taga[pre];
    tagb[now] = tagb[pre];
  }
  return now;
}
void query(int root, int l, int r, int x) {
  A += taga[root];
  B += tagb[root];
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (x <= mid)
    query(lch[root], l, mid, x);
  else
    query(rch[root], mid + 1, r, x);
}
int main() {
  scanf("%d", &n);
  root[0] = lch[0] = rch[0] = 0;
  for (int i = 1; i <= n; i++) {
    int x1, x2, y1, y2, a, b;
    scanf("%d%d%d%d%d%d", &x1, &x2, &y1, &a, &b, &y2);
    root[i] = root[i - 1];
    root[i] = modify(root[i], 0, 200001, 1, x1, 0, y1);
    root[i] = modify(root[i], 0, 200001, x1 + 1, x2, a, b);
    root[i] = modify(root[i], 0, 200001, x2 + 1, 200001, 0, y2);
  }
  scanf("%d", &T);
  while (T--) {
    int l, r, x;
    scanf("%d%d%d", &l, &r, &x);
    x = (ans + x) % 1000000000;
    x = min(x, 200001);
    A = B = 0;
    query(root[r], 0, 200001, x);
    ans = A * x + B;
    A = B = 0;
    query(root[l - 1], 0, 200001, x);
    ans -= A * x + B;
    printf("%I64d\n", ans);
  }
  return 0;
}
