#include <bits/stdc++.h>
using namespace std;
vector<int> vr;
long long a, b, n;
long long sum(long long id) {
  if (id == 0) return 0;
  long long ret = id * a;
  ret += id * (id - 1) * b / 2;
  return ret;
}
int main() {
  cin >> a >> b >> n;
  for (int i = 0; i < n; i++) {
    long long l, t, m;
    cin >> l >> t >> m;
    long long st = l, en = 2e6;
    long long opt = -1;
    while (st <= en) {
      long long mid = (st + en) / 2;
      long long v = sum(mid) - sum(l - 1);
      long long temp = m;
      if (sum(mid) - sum(mid - 1) <= t && m * t >= sum(mid) - sum(l - 1)) {
        opt = max(opt, mid);
        st = mid + 1;
      } else
        en = mid - 1;
      m = temp;
    }
    cout << opt << endl;
  }
  return 0;
}
