#include <bits/stdc++.h>
using namespace std;
long long a, b, n, l, t, m;
long long cum[2000001], h[2000001];
long long high(long long i) { return (a + ((i - 1) * b)); }
void gen() {
  cum[1] = high(1);
  h[1] = high(1);
  for (int i = 2; i <= 2000000; i++) {
    cum[i] += (high(i) + cum[i - 1]);
    h[i] = high(i);
  }
}
bool valid(long long mid) {
  long long sum = cum[mid] - cum[l - 1];
  long long maxx = h[mid];
  return (sum <= m * t) && (maxx <= t);
}
int main() {
  while (scanf("%lld%lld%lld", &a, &b, &n) != EOF) {
    gen();
    while (n--) {
      scanf("%lld%lld%lld", &l, &t, &m);
      if (high(l) > t) {
        printf("-1\n");
        continue;
      }
      long long lo = 1, hi = 2e6, mid;
      while (lo < hi) {
        mid = (lo + hi) / 2;
        if (valid(mid))
          lo = mid;
        else
          hi = mid - 1;
        if (lo + 1 == hi) {
          if (valid(lo + 1))
            lo = hi;
          else
            hi = lo;
        }
      }
      printf("%lld\n", lo);
    }
  }
  return 0;
}
