#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, n;
  scanf("%lld %lld %lld", &a, &b, &n);
  for (long long i = 0; i < n; i++) {
    long long l, t, m;
    scanf("%lld %lld %lld", &l, &t, &m);
    long long high = 10000002;
    long long low = -1;
    while (high != low + 1) {
      long long mid = low + (high - low) / 2;
      long long count = mid;
      long long sumt =
          (count * (count + 1)) / 2 * b + (count + 1) * (a + (l - 1) * b);
      long long maxt = (l + count - 1) * b + a;
      if (maxt <= t && sumt <= m * t) {
        low = mid;
      } else {
        high = mid;
      }
    }
    if (low != -1) {
      printf("%lld\n", low + l);
    } else {
      printf("-1\n");
    }
  }
  return 0;
}
