#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  long long A, B, n;
  cin >> A >> B >> n;
  while (n--) {
    long long l, t, m;
    cin >> l >> t >> m;
    if (t < A + (l - 1) * B) {
      cout << -1 << endl;
      continue;
    }
    long long low = l, high = 1e7 * 1ll;
    while (low < high) {
      long long mi = (low + high + 1) / 2;
      long long res = (mi - l + 1) * A;
      res += (((mi - 1) * mi) / 2 - max(0ll, ((l - 2) * (l - 1)) / 2)) * B;
      if (res <= t * m && A + (mi - 1) * B <= t) {
        low = mi;
      } else {
        high = mi - 1;
      }
    }
    cout << low << endl;
  }
  return 0;
}
