#include <bits/stdc++.h>
using namespace std;
struct linear {
  int id, a, b;
  bool operator<(const linear &o) const { return id < o.id; }
};
struct layer {
  vector<linear> who;
  vector<int> suma;
  vector<long long> sumb;
  layer() : suma(1), sumb(1) {}
  layer(linear l) : who(1, l) {
    suma = vector<int>{0, l.a}, sumb = vector<long long>{0, l.b};
  }
};
void merge(const vector<linear> &l, const vector<linear> &r,
           vector<linear> &to) {
  to.resize((int)(l).size() + (int)(r).size());
  merge((l).begin(), (l).end(), (r).begin(), (r).end(), to.begin());
}
layer merge(const layer &l, const layer &r) {
  layer ans;
  merge(l.who, r.who, ans.who);
  ans.suma.resize((int)(ans.who).size() + 1);
  ans.sumb.resize((int)(ans.who).size() + 1);
  for (int i = 0; i < (int)((int)(ans.who).size()); ++i) {
    ans.suma[i + 1] = ans.suma[i] + ans.who[i].a;
    ans.sumb[i + 1] = ans.sumb[i] + ans.who[i].b;
  }
  return ans;
}
pair<int, long long> combine(const pair<int, long long> &l,
                             const pair<int, long long> &r) {
  return pair<int, long long>(l.first + r.first, l.second + r.second);
}
const int mod = (int)1e9;
struct segtree {
  vector<layer> val;
  int tsz;
  segtree(const vector<linear> &v) {
    tsz = (int)(v).size();
    val.resize(2 * tsz);
    for (int i = 0; i < (int)((int)(v).size()); ++i) val[i + tsz] = layer(v[i]);
    for (int i = ((int)(tsz)-1); i >= 0; --i)
      val[i] = merge(val[2 * i], val[2 * i + 1]);
  }
  pair<int, long long> query(int v, int idl, int idr) {
    linear cl{idl, -1, -1}, cr{idr, -1, -1};
    int posl = 0;
    if (idl != 0)
      posl = lower_bound((val[v].who).begin(), (val[v].who).end(), cl) -
             val[v].who.begin();
    int posr = (int)(val[v].who).size();
    if (idr != mod)
      posr = lower_bound((val[v].who).begin(), (val[v].who).end(), cr) -
             val[v].who.begin();
    return make_pair(val[v].suma[posr] - val[v].suma[posl],
                     val[v].sumb[posr] - val[v].sumb[posl]);
  }
  pair<int, long long> query(int l, int r, int idl, int idr) {
    pair<int, long long> ans(0, 0);
    for (l += tsz, r += tsz; l < r; l >>= 1, r >>= 1) {
      if (l & 1) ans = combine(ans, query(l++, idl, idr));
      if (r & 1) ans = combine(ans, query(--r, idl, idr));
    }
    return ans;
  }
};
void solve(int n) {
  vector<linear> l, m, r;
  for (int i = 0; i < (int)(n); ++i) {
    int x1, x2, y1, a, b, y2;
    cin >> x1 >> x2 >> y1 >> a >> b >> y2;
    l.push_back(linear{x1, -a, y1 - b});
    m.push_back(linear{i, a, b});
    r.push_back(linear{x2, -a, y2 - b});
  }
  segtree dl(l), dm(m), dr(r);
  long long last = 0;
  int q;
  cin >> q;
  for (int i = 0; i < (int)(q); ++i) {
    int cl, cr, x;
    cin >> cl >> cr >> x;
    x = (x + last) % mod;
    --cl;
    pair<int, long long> ans = dm.query(cl, cr, 0, mod);
    ans = combine(ans, dl.query(cl, cr, x, mod));
    ans = combine(ans, dr.query(cl, cr, 0, x));
    last = ((long long)ans.first * x + ans.second);
    cout << last << endl;
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  while (cin >> n) solve(n);
}
