#include <bits/stdc++.h>
using namespace std;
long long A, B, n, l, t, m, s;
inline long long comb(long long first) { return (first * (first - 1LL)) / 2LL; }
inline long long h(long long i) { return A + (i - 1LL) * B; }
inline bool check(long long r) {
  long long e = comb(r) - comb(l - 1LL);
  if (B && (long double)e > 2e18 / (long double)B) return false;
  if (h(r) > t) return false;
  s = m * t;
  s -= e * B;
  s -= A * (r - l + 1LL);
  return (s >= 0LL);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> A >> B >> n;
  while (n--) {
    cin >> l >> t >> m;
    if (h(l) > t) {
      cout << -1 << '\n';
      continue;
    }
    long long lo = l, hi = max(t, m) + l + 5;
    while (lo < hi) {
      long long mid = (lo + hi) / 2LL;
      if (check(mid))
        lo = mid;
      else
        hi = mid - 1LL;
      if (lo + 1LL == hi) {
        if (check(hi))
          lo = hi;
        else
          hi = lo;
      }
    }
    cout << lo << '\n';
  }
}
