#include <bits/stdc++.h>
using namespace std;
long long get(long long a, long long b, long long x, long long y) {
  x--;
  y--;
  long long sum = (y * (y - 1) - x * (x - 1)) / 2;
  return a * (y - x) + sum * b;
}
int main() {
  long long a, b, q;
  ios_base::sync_with_stdio(false);
  cin >> a >> b >> q;
  while (q--) {
    long long l, t, m;
    cin >> l >> t >> m;
    long long lll = l, rr = 2e6 + 5;
    while (rr - lll > 1) {
      long long mid = (lll + rr) / 2;
      if (a + (mid - 2) * b <= t && get(a, b, l, mid) <= t * m)
        lll = mid;
      else
        rr = mid;
    }
    if (lll == l) lll = 0;
    cout << lll - 1 << endl;
  }
}
