#include <bits/stdc++.h>
using namespace std;
long long a, b, m;
long long sumUpto(long long idx) {
  long long sum = idx * (2 * a + (idx - 1) * b);
  return sum >> 1;
}
long long bs(long long l, long long h, long long m, long long t) {
  long long low = l, high = h, mid;
  while (low <= high) {
    mid = (low + high) >> 1;
    long long cutArea = min(mid - l + 1, m) * t;
    long long reqArea = sumUpto(mid) - sumUpto(l - 1);
    if (reqArea <= cutArea && a + (mid - 1) * b <= t)
      low = mid + 1;
    else
      high = mid - 1;
  }
  return high;
}
int main() {
  int q;
  cin >> a >> b >> q;
  while (q--) {
    long long l, t;
    cin >> l >> t >> m;
    long long res = bs(l, 1000000000LL, m, t);
    if (res < l)
      cout << -1 << endl;
    else
      cout << res << endl;
  }
  return 0;
}
