#include <bits/stdc++.h>
using namespace std;
long long A, B, n;
int solve(long long left, long long t, long long me) {
  long long l = left, r = 1000 * 1000 + 1;
  while (l < r) {
    long long m = (l + r) / 2 + 1;
    if (t >= A + B * (m - 1) &&
        t * me >= ((m - left + 1) * (A + (left - 1) * B) +
                   (m - left) * (m - left + 1) / 2 * B)) {
      l = m;
    } else {
      r = m - 1;
    }
  }
  if (l == r && t < A + B * (l - 1)) {
    return -1;
  } else {
    return r;
  }
}
void solve() {
  cin >> A >> B >> n;
  ;
  for (int i = 0; i < n; i++) {
    long long l, t, m;
    cin >> l >> t >> m;
    cout << solve(l, t, m) << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
