1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <vector>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  const long long MOD = 1e9 + 7;
  int n, q;
  int start, end;
  long long x = 1;
  bool mod;
  cin >> n >> q;
  vector<long long> l(n), r(n);
  for (int i = 0; i < n; ++i) {
    cin >> l[i] >> r[i];
  }
  for (int i = 0; i < q; ++i) {
    cin >> x >> start >> end;
    mod = false;
    for (int j = start; j < end; ++j) {
      if ((mod && r[j] > 1) || x * r[j] > x + l[j]) {
        x *= r[j];
      } else {
        x += l[j];
      }
      if (x != x % MOD) {
        mod = true;
        x %= MOD;
      }
    }
    cout << x << endl;
  }
}