#include <bits/stdc++.h>
using namespace std;
long long A, B, n, l, t, m, r;
long long S(long long i) { return A + ((i - 1) * B); }
long long Z(long long p, long long q) {
  return ((q - p + 1) * (S(p) + S(q))) / 2;
}
int main() {
  scanf("%ld %ld %ld\n", &A, &B, &n);
  while (n--) {
    scanf("%ld %ld %ld\n", &l, &t, &m);
    if (S(l) > t) {
      printf("-1\n");
      continue;
    }
    long long lo = l, la = 10e7;
    while (lo < la) {
      long long mid = (lo + la) / 2;
      if (S(mid) <= t && Z(l, mid) <= m * t) {
        lo = mid + 1;
      } else {
        la = mid;
      }
    }
    printf("%ld\n", lo - 1);
  }
  return 0;
}
