#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, n;
  cin >> a >> b >> n;
  for (register int i = 1; i <= n; ++i) {
    long long l, t, m;
    cin >> l >> t >> m;
    long long st = l;
    long long dr = 2000000;
    long long ans = -1;
    while (st <= dr) {
      long long mij = (st + dr) / 2;
      long long lb = l;
      long long ub = mij;
      if (a + (mij - 1) * b <= t and
          (ub - lb + 1) * a +
                  (((ub - 1) * ub) / 2 - ((lb - 1) * (lb - 2)) / 2) * b <=
              m * t) {
        ans = mij;
        st = mij + 1;
      } else
        dr = mij - 1;
    }
    cout << ans << '\n';
  }
  return 0;
}
