#include <bits/stdc++.h>
using namespace std;
const long long NMAX = 1e6 + 6;
vector<long long> pre(NMAX, 0);
vector<long long> ar;
signed main() {
  ios_base::sync_with_stdio(false);
  long long a, b, n;
  cin >> a >> b >> n;
  pre[1] = a;
  for (long long i = 2; i <= NMAX; i++) pre[i] = a + ((i - 1) * b);
  ar = pre;
  for (long long i = 2; i <= NMAX; i++) pre[i] += pre[i - 1];
  while (n--) {
    long long l, t, m;
    cin >> l >> t >> m;
    long long can = t * m;
    long long bas = l, son = NMAX;
    while (bas + 1 < son) {
      long long mid = (bas + son) / 2;
      if (pre[mid] - pre[l - 1] <= can and ar[mid] <= t)
        bas = mid;
      else
        son = mid;
    }
    if (bas >= l and ar[bas] <= t) {
      cout << bas << "\n";
    } else {
      cout << -1 << "\n";
    }
  }
  return 0;
}
