#include <bits/stdc++.h>
using namespace std;
long long a, b, n;
long long l, t, m;
long long getnum(long long x) { return a + (x - 1) * b; }
long long getsum(long long r) {
  return (getnum(r) + getnum(l)) * (r - l + 1) / 2;
}
int main() {
  while (~scanf("%lld%lld%lld", &a, &b, &n)) {
    while (n--) {
      scanf("%lld%lld%lld", &l, &t, &m);
      if (getnum(l) > t) {
        printf("-1\n");
        continue;
      }
      long long li = l;
      long long ri = (t - a) / b + 1;
      while (li <= ri) {
        long long mid = (li + ri) >> 1;
        if (getsum(mid) <= t * m)
          li = mid + 1;
        else
          ri = mid - 1;
      }
      printf("%lld\n", li - 1);
    }
  }
  return 0;
}
