#include <bits/stdc++.h>
using namespace std;
struct fast_ios {
  fast_ios() {
    cin.tie(nullptr), ios::sync_with_stdio(false),
        cout << fixed << setprecision(20);
  };
} fast_ios_;
template <class T>
auto add = [](T a, T b) -> T { return a + b; };
template <class T>
auto f_max = [](T a, T b) -> T { return max(a, b); };
template <class T>
auto f_min = [](T a, T b) -> T { return min(a, b); };
template <class T>
using V = vector<T>;
using Vl = V<long long int>;
using VVl = V<Vl>;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (int i = 0; i < (int)v.size(); i++)
    os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& in : v) is >> in;
  return is;
}
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
long long int gcd(long long int a, long long int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long int ceil(long long int a, long long int b) { return (a + b - 1) / b; }
long long int digit(long long int a) { return (long long int)log10(a); }
long long int e_dist(pair<long long int, long long int> a,
                     pair<long long int, long long int> b) {
  return abs(a.first - b.first) * abs(a.first - b.first) +
         abs(a.second - b.second) * abs(a.second - b.second);
}
long long int m_dist(pair<long long int, long long int> a,
                     pair<long long int, long long int> b) {
  return abs(a.first - b.first) + abs(a.second - b.second);
}
bool check_overflow(long long int a, long long int b, long long int limit) {
  if (b == 0) return false;
  return a > limit / b;
}
void Worshall_Floyd(VVl& g) {
  for (long long int k = (0), k_end_ = (((long long int)(g).size()));
       k < k_end_; ++k)
    for (long long int i = (0), i_end_ = (((long long int)(g).size()));
         i < i_end_; ++i)
      for (long long int j = (0), j_end_ = (((long long int)(g).size()));
           j < j_end_; ++j)
        chmin(g[i][j], g[i][k] + g[k][j]);
}
const long long int MOD1000000007 = 1000000007, MOD998244353 = 998244353,
                    INF = 5e18;
long long int dx[8] = {1, 0, -1, 0, 1, -1, 1, -1},
              dy[8] = {0, 1, 0, -1, -1, -1, 1, 1};
bool YN(bool flag) {
  cout << (flag ? "YES" : "NO") << '\n';
  return flag;
}
bool yn(bool flag) {
  cout << (flag ? "Yes" : "No") << '\n';
  return flag;
}
struct Edge {
  long long int from, to;
  long long int cost;
  Edge() {}
  Edge(long long int u, long long int v, long long int c) {
    cost = c;
    from = u;
    to = v;
  }
  bool operator<(const Edge& e) const { return cost < e.cost; }
};
struct WeightedEdge {
  long long int to;
  long long int cost;
  WeightedEdge(long long int v, long long int c = 1) {
    to = v;
    cost = c;
  }
  bool operator<(const WeightedEdge& e) const { return cost < e.cost; }
};
using WeightedGraph = V<V<WeightedEdge>>;
struct TmpFunc {
  long long int x1;
  long long int x2;
  long long int y1;
  long long int a;
  long long int b;
  long long int y2;
  TmpFunc() {}
  TmpFunc(Vl input) {
    x1 = input[0];
    x2 = input[1];
    y1 = input[2];
    a = input[3];
    b = input[4];
    y2 = input[5];
  }
  long long int get_val(long long int k) {
    if (k <= x1)
      return y1;
    else if (k <= x2)
      return a * k + b;
    else
      return y2;
  }
};
const long long int FIX = 300;
const long long int MAX_X = 200100;
const long long int MOD = 1e9;
long long int N, Q;
int main() {
  cin >> N;
  VVl BucketSum1(N / FIX + 1, Vl(MAX_X + 1));
  VVl BucketSum2(N / FIX + 1, Vl(MAX_X + 1));
  V<TmpFunc> arr(N);
  Vl _input(6);
  for (long long int i = (0), i_end_ = (N); i < i_end_; ++i) {
    cin >> _input;
    arr[i] = TmpFunc(_input);
    BucketSum1[i / FIX][arr[i].x1 + 1] += arr[i].a;
    BucketSum1[i / FIX][arr[i].x2 + 1] -= arr[i].a;
    BucketSum2[i / FIX][0] += arr[i].y1;
    BucketSum2[i / FIX][arr[i].x1 + 1] -= arr[i].y1;
    BucketSum2[i / FIX][arr[i].x1 + 1] += arr[i].b;
    BucketSum2[i / FIX][arr[i].x2 + 1] -= arr[i].b;
    BucketSum2[i / FIX][arr[i].x2 + 1] += arr[i].y2;
  }
  for (long long int i = (0), i_end_ = (N / FIX + 1); i < i_end_; ++i) {
    for (long long int j = (0), j_end_ = (MAX_X); j < j_end_; ++j) {
      BucketSum1[i][j + 1] += BucketSum1[i][j];
      BucketSum2[i][j + 1] += BucketSum2[i][j];
    }
  }
  long long int prv = 0;
  cin >> Q;
  for (long long int _ = (0), __end_ = (Q); _ < __end_; ++_) {
    long long int l, r, x;
    cin >> l >> r >> x;
    l--;
    long long int val = (prv + x) % MOD;
    long long int pos = min(val, MAX_X);
    long long int a_sum = 0, b_sum = 0, sum = 0;
    if (r - l > 2 * FIX) {
      for (long long int k = (l), k_end_ = (ceil(l, FIX) * FIX); k < k_end_;
           ++k) {
        sum += arr[k].get_val(val);
      }
      for (long long int k = (r / FIX * FIX), k_end_ = (r); k < k_end_; ++k) {
        sum += arr[k].get_val(val);
      }
      for (long long int k = (ceil(l, FIX)), k_end_ = (r / FIX); k < k_end_;
           ++k) {
        a_sum += BucketSum1[k][pos];
        b_sum += BucketSum2[k][pos];
      }
    } else {
      for (long long int k = (l), k_end_ = (r); k < k_end_; ++k)
        sum += arr[k].get_val(val);
    }
    sum += a_sum * val + b_sum;
    prv = sum % MOD;
    cout << sum << '\n';
  }
}
