#include <bits/stdc++.h>
using namespace std;
mt19937 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long a, b;
  int n;
  cin >> a >> b >> n;
  auto val = [&](long long x) { return a + (x - 1) * b; };
  auto sum = [&](long long l, long long r) {
    return ((r - l + 1) * (val(l) + val(r))) / 2;
  };
  auto query = [&](long long l, long long t, long long m) -> long long {
    if (val(l) > t) return -1;
    long long lo = l, hi = (t - a) / b + 3;
    while (lo <= hi) {
      long long mid = lo + (hi - lo) / 2;
      if (val(mid) <= t and sum(l, mid) <= t * m)
        lo = mid + 1;
      else
        hi = mid - 1;
    }
    return hi;
  };
  while (n--) {
    long long l, t, m;
    cin >> l >> t >> m;
    cout << query(l, t, m) << endl;
  }
}
