#include <bits/stdc++.h>
using namespace std;
int n, a, b;
long long height(long long i) { return (1ll) * a + (i - 1) * b; }
long long sum(long long l, long long r) {
  return a * (1ll) * (r - l + 1) +
         b * (r * (r - 1) / 2 - ((l - 1) * (l - 2) / 2));
}
int main() {
  cin >> a >> b >> n;
  for (long long i = 0; i < n; i++) {
    int l, t, m;
    cin >> l >> t >> m;
    if (height(l) > t)
      printf("%d\n", -1);
    else {
      long long left = l, right = 2e6 + 5;
      while (right - left > 1) {
        long long mid = (left + right) / 2;
        if (height(mid - 1) <= t && sum(l, mid - 1) <= (1ll) * t * m)
          left = mid;
        else
          right = mid;
      }
      cout << left - 1 << "\n";
    }
  }
}
