#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
int main() {
  long long n, A, B;
  cin >> A >> B >> n;
  int N = 2000011;
  std::vector<long long> h(N);
  std::vector<long long> sumh(N);
  long long curh = A - B;
  h[0] = 0;
  sumh[0] = 0;
  long long curs = 0;
  for (int i = 1; i < N; i++) {
    curh += B;
    h[i] = curh;
    curs += curh;
    sumh[i] = curs;
  }
  long long l, t, m;
  for (int i = 0; i < n; i++) {
    cin >> l >> t >> m;
    long long r1 = upper_bound((h).begin(), (h).end(), t) - h.begin() - 1;
    long long r2 =
        upper_bound((sumh).begin(), (sumh).end(), m * t + sumh[l - 1]) -
        sumh.begin() - 1;
    long long r = min(r1, r2);
    if (r >= l)
      cout << r << endl;
    else
      cout << -1 << endl;
  }
}
