#include <bits/stdc++.h>
using namespace std;
long long a, b, n;
long long sum(long long x) { return a * x + x * (x - 1) / 2 * b; }
int main() {
  cin >> a >> b >> n;
  for (int i = 0; i < n; ++i) {
    long long l, t, m;
    cin >> l >> t >> m;
    long long r = -1;
    long long lo = l, hi = 2000004, mid;
    while (hi >= lo) {
      mid = (lo + hi) / 2;
      long long val = sum(mid) - sum(l - 1);
      long long maxv = a + b * (mid - 1);
      if (maxv > t || val > t * m)
        hi = mid - 1;
      else {
        r = mid;
        lo = mid + 1;
      }
    }
    cout << r << endl;
  }
}
