#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
template <typename T>
T PrLLBits(T val) {
  long long int bits = sizeof(T) * 8;
  for (long long int i = 0; i < bits; i++)
    printf("%I64d%s", (val >> (bits - 1 - i)) & 1,
           i % 4 == 3 && i != bits - 1 ? " " : "");
}
long long int A, B, N;
long long int L, T, M;
long long int Bites(long long int R) {
  long long int a1 = (A + (L - 1) * B);
  long long int an = (A + (R - 1) * B);
  long long int sum = ((a1 + an) * (R - L + 1)) / 2;
  long long int bites = sum / M + 1 - (sum % M == 0);
  return bites;
}
int main() {
  scanf("%I64d%I64d%I64d", &A, &B, &N);
  for (long long int i = 0; i < N; i++) {
    scanf("%I64d%I64d%I64d", &L, &T, &M);
    if ((A + (L - 1) * B) > T) {
      printf("-1\n");
      continue;
    }
    long long int start = L;
    long long int end = 1000000000LL;
    long long int R, prev = -1;
    while (true) {
      R = (start + end) / 2;
      if (R == prev) break;
      prev = R;
      long long int bites = Bites(R);
      if (bites > T || (A + (R - 1) * B) > T)
        end = R;
      else
        start = R;
    }
    printf("%I64d\n", R);
  }
  return 0;
}
