#include <bits/stdc++.h>
using namespace std;
long long int n, l, lefti, r, mid, a, b, m, t;
void BS() {
  l = lefti, r = (t - a) / b + 1;
  while (l < r) {
    mid = (l + r + 1) / 2;
    if ((2 * a + b * (lefti + mid - 2)) * (mid - lefti + 1) / 2 <= t * m &&
        a + b * (mid - 1) <= t)
      l = mid;
    else
      r = mid - 1;
  }
  if ((2 * a + b * (lefti + l - 2)) * (l - lefti + 1) / 2 <= t * m &&
      a + b * (l - 1) <= t)
    cout << l << endl;
  else
    cout << -1 << endl;
}
int main() {
  cin >> a >> b >> n;
  while (n--) {
    cin >> lefti >> t >> m;
    BS();
  }
  return 0;
}
