#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long A, B, q;
  cin >> A >> B >> q;
  while (q--) {
    long long l, t, m;
    cin >> l >> t >> m;
    if (A + (l - 1) * B > t) {
      cout << -1 << '\n';
      continue;
    }
    long long low = l;
    long long high = 1e7;
    auto s = [&](long long x) { return x * (x + 1) / 2; };
    auto sum = [&](long long l, long long r) {
      return A * (r - l + 1) + B * (s(r - 1) - s(max(0LL, l - 2)));
    };
    while (low != high) {
      long long mid = (low + high + 1) >> 1;
      if (A + (mid - 1) * B <= t and sum(l, mid) <= m * t) {
        low = mid;
      } else {
        high = mid - 1;
      }
    }
    cout << low << '\n';
  }
  return (0);
}
