#include <bits/stdc++.h>
using namespace std;
long long int a, b;
int n;
long long int l, t, m;
long long int f(long long int k) { return a + (k - 1) * b; }
long long int sum(long long int k) { return ((f(k) + a) * k) / 2; }
int main() {
  cin >> a >> b >> n;
  for (int i = 0; i < n; i++) {
    cin >> l >> t >> m;
    long long int lo = l, hi = 1e9, ans = -1;
    while (lo <= hi) {
      long long int mid = (lo + hi) >> 1;
      if (f(mid) <= t && sum(mid) - sum(l - 1) <= t * m) {
        ans = mid;
        lo = mid + 1;
      } else
        hi = mid - 1;
    }
    cout << ans << endl;
  }
  return 0;
}
