#include <bits/stdc++.h>
using namespace std;
long long A, B, N;
long long L, T, M;
bool ok(long long R) {
  long long mx = A + (R - 1) * B;
  long long mn = A + (L - 1) * B;
  long long D = R - L;
  if (mx > T) return false;
  return (mn * (D + 1) + B * D * (D + 1) / 2) <= T * M;
}
int main(void) {
  cin >> A >> B >> N;
  while (N--) {
    cin >> L >> T >> M;
    long long R = L;
    long long mn = A + (L - 1) * B;
    if (mn > T) {
      R = -1;
    } else {
      long long XR = 1LL << 22;
      while (XR > R) {
        long long m = (R + XR) / 2;
        if (!ok(m))
          XR = m;
        else
          R = m + 1;
      }
      R -= 1;
    }
    cout << R << '\n';
  }
  return 0;
}
