#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005000;
long long A, B;
long long cnt(long long x) { return x * A + B * x * (x - 1) / 2LL; }
bool can(long long st, long long i, long long m, long long t) {
  long long sum = cnt(i) - cnt(st - 1);
  return m * t >= sum && t >= A + (i - 1) * B;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> A >> B >> n;
  for (int i = 0; i < n; ++i) {
    int l, t, m;
    cin >> l >> t >> m;
    long long lo = l, hi = 1e9;
    long long best = -1;
    while (lo <= hi) {
      long long mid = (lo + hi) >> 1;
      if (can(l, mid, m, t))
        best = mid, lo = mid + 1;
      else
        hi = mid - 1;
    }
    cout << best << '\n';
  }
  return 0;
}
