#include <bits/stdc++.h>
using namespace std;
long long A, B, n, l, t, m;
long long sm(long long le, long long re) {
  long long an;
  an = (re * (re - 1)) / 2;
  if (le > 1) an -= (((le - 1) * (le - 2)) / 2);
  an *= B;
  return an + A * (re - le + 1);
}
long long fun(long long le, long long re) {
  if (le == re) return le;
  long long i, j, k;
  k = (le + re) / 2;
  k++;
  if (sm(l, k) > m * t)
    return fun(le, k - 1);
  else
    return fun(k, re);
}
int main() {
  int i, j, k;
  cin >> A >> B >> n;
  for (i = 0; i < n; i++) {
    cin >> l >> t >> m;
    k = (t - A) / B;
    if (k + 1 < l) {
      cout << -1 << endl;
      continue;
    }
    cout << fun(l, k + 1) << endl;
  }
  return 0;
}
