#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
long long int INF = 1e12;
long long int n, m;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int i, j, t, k, x, y, z, N;
  long long int a, b;
  cin >> a >> b >> n;
  for (i = 0; i < n; i++) {
    cin >> x >> t >> m;
    long long int l = x, r = 1e10, mid, ans = -1;
    while (l <= r) {
      mid = (l + r) / 2;
      long long int flg = 0;
      if (a + (mid - 1) * b > t) flg = 1;
      long long int sum = (a - b) * (mid - x + 1);
      sum += b * ((mid * (mid + 1)) / 2 - ((x - 1) * x) / 2);
      if (sum > m * t) flg = 1;
      if (flg) {
        r = mid - 1;
      } else {
        ans = mid;
        l = mid + 1;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
