#include <bits/stdc++.h>
using namespace std;
long long a, b, n;
long long l, t, m;
long long le, ri, start, end;
long long solve() {
  long long ans = -1, mid, tmp, now;
  le = l;
  ri = 1000000LL;
  start = a + (le - 1LL) * b;
  while (le <= ri) {
    mid = le + ri >> 1;
    now = a + (mid - 1) * b;
    tmp = (start + now) * (mid - l + 1) / 2;
    if (tmp <= t * m && now <= t) {
      ans = mid;
      le = mid + 1;
    } else {
      ri = mid - 1;
    }
  }
  return ans;
}
int main() {
  std::ios::sync_with_stdio(false);
  while (cin >> a >> b >> n) {
    while (n--) {
      cin >> l >> t >> m;
      cout << solve() << endl;
    }
  }
}
