#include <bits/stdc++.h>
using namespace std;
long long A, B, n, l, t, m;
bool check(long long index) {
  long long ai = A + (index - 1) * B;
  if (ai > t) {
    return false;
  }
  long long num = (index - l + 1) * (A + (l - 1) * B + A + (index - 1) * B) / 2;
  if (num > m * t) return false;
  return true;
}
int main() {
  cin >> A >> B >> n;
  while (n--) {
    cin >> l >> t >> m;
    long long lo = l, hi = max(t, m) + l + 5, mid;
    long long ans = -1ll;
    while (lo <= hi) {
      mid = (lo + hi) >> 1;
      if (check(mid)) {
        lo = mid + 1;
        ans = max<long long>(ans, mid);
      } else {
        hi = mid - 1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
