#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
const int N = 1e6 + 11, M = (int)1e7 + 1;
long long A, B, n, l, t, m;
long long check(long long r) {
  long long val =
      A * (r - l + 1) + (r * (r - 1) / 2 - (l - 1) * (l - 2) / 2) * B;
  return (A + (r - 1) * B <= t and val <= m * t);
}
long long slv() {
  long long p = l, q = (long long)1e6, ans = 0;
  while (p <= q) {
    long long mid = (p + q) / 2;
    if (check(mid)) {
      p = mid + 1;
      ans = max(ans, mid);
    } else
      q = mid - 1;
  }
  return ans;
}
void solve() {
  cin >> A >> B >> n;
  for (int i = 0; i < n; i++) {
    cin >> l >> t >> m;
    long long r = slv();
    cout << ((l <= r) ? r : -1) << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  solve();
  return 0;
}
